Add some metrics

This commit is contained in:
Erik Johnston 2016-11-21 17:34:43 +00:00
parent 50934ce460
commit 88d85ebae1

View file

@ -31,10 +31,16 @@ Events are replicated via a separate events stream.
from .units import Edu from .units import Edu
from synapse.util.metrics import Measure
import synapse.metrics
from blist import sorteddict from blist import sorteddict
import ujson import ujson
metrics = synapse.metrics.get_metrics_for(__name__)
PRESENCE_TYPE = "p" PRESENCE_TYPE = "p"
KEYED_EDU_TYPE = "k" KEYED_EDU_TYPE = "k"
EDU_TYPE = "e" EDU_TYPE = "e"
@ -49,8 +55,6 @@ class FederationRemoteSendQueue(object):
self.server_name = hs.hostname self.server_name = hs.hostname
self.clock = hs.get_clock() self.clock = hs.get_clock()
# TODO: Add metrics for size of lists below
self.presence_map = {} self.presence_map = {}
self.presence_changed = sorteddict() self.presence_changed = sorteddict()
@ -61,10 +65,24 @@ class FederationRemoteSendQueue(object):
self.failures = sorteddict() self.failures = sorteddict()
self.device_messages = sorteddict()
self.pos = 1 self.pos = 1
self.pos_time = sorteddict() self.pos_time = sorteddict()
self.device_messages = sorteddict() # EVERYTHING IS SAD. In particular, python only makes new scopes when
# we make a new function, so we need to make a new function so the inner
def register(name, queue):
metrics.register_callback(
queue_name + "_size",
lambda: len(queue),
)
for queue_name in [
"presence_map", "presence_changed", "keyed_edu", "keyed_edu_changed",
"edus", "failures", "device_messages", "pos_time",
]:
register(queue_name, getattr(self, queue_name))
self.clock.looping_call(self._clear_queue, 30 * 1000) self.clock.looping_call(self._clear_queue, 30 * 1000)
@ -76,7 +94,6 @@ class FederationRemoteSendQueue(object):
def _clear_queue(self): def _clear_queue(self):
"""Clear the queues for anything older than N minutes""" """Clear the queues for anything older than N minutes"""
# TODO measure this function time.
FIVE_MINUTES_AGO = 5 * 60 * 1000 FIVE_MINUTES_AGO = 5 * 60 * 1000
now = self.clock.time_msec() now = self.clock.time_msec()
@ -94,6 +111,7 @@ class FederationRemoteSendQueue(object):
def _clear_queue_before_pos(self, position_to_delete): def _clear_queue_before_pos(self, position_to_delete):
"""Clear all the queues from before a given position""" """Clear all the queues from before a given position"""
with Measure(self.clock, "send_queue._clear"):
# Delete things out of presence maps # Delete things out of presence maps
keys = self.presence_changed.keys() keys = self.presence_changed.keys()
i = keys.bisect_left(position_to_delete) i = keys.bisect_left(position_to_delete)
@ -104,7 +122,9 @@ class FederationRemoteSendQueue(object):
user_id for uids in self.presence_changed.values() for _, user_id in uids user_id for uids in self.presence_changed.values() for _, user_id in uids
) )
to_del = [user_id for user_id in self.presence_map if user_id not in user_ids] to_del = [
user_id for user_id in self.presence_map if user_id not in user_ids
]
for user_id in to_del: for user_id in to_del:
del self.presence_map[user_id] del self.presence_map[user_id]