mirror of
https://mau.dev/maunium/synapse.git
synced 2024-12-16 03:33:51 +01:00
Add CPU metrics for _fetch_event_list
add a Measure block on _fetch_event_list, in the hope that we can better measure CPU usage here.
This commit is contained in:
parent
395fa8d1fd
commit
e31e5dee38
1 changed files with 32 additions and 19 deletions
|
@ -222,25 +222,39 @@ class EventsWorkerStore(SQLBaseStore):
|
||||||
"""Takes a database connection and waits for requests for events from
|
"""Takes a database connection and waits for requests for events from
|
||||||
the _event_fetch_list queue.
|
the _event_fetch_list queue.
|
||||||
"""
|
"""
|
||||||
event_list = []
|
|
||||||
i = 0
|
i = 0
|
||||||
while True:
|
while True:
|
||||||
|
with self._event_fetch_lock:
|
||||||
|
event_list = self._event_fetch_list
|
||||||
|
self._event_fetch_list = []
|
||||||
|
|
||||||
|
if not event_list:
|
||||||
|
single_threaded = self.database_engine.single_threaded
|
||||||
|
if single_threaded or i > EVENT_QUEUE_ITERATIONS:
|
||||||
|
self._event_fetch_ongoing -= 1
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
self._event_fetch_lock.wait(EVENT_QUEUE_TIMEOUT_S)
|
||||||
|
i += 1
|
||||||
|
continue
|
||||||
|
i = 0
|
||||||
|
|
||||||
|
self._fetch_event_list(conn, event_list)
|
||||||
|
|
||||||
|
def _fetch_event_list(self, conn, event_list):
|
||||||
|
"""Handle a load of requests from the _event_fetch_list queue
|
||||||
|
|
||||||
|
Args:
|
||||||
|
conn (twisted.enterprise.adbapi.Connection): database connection
|
||||||
|
|
||||||
|
event_list (list[Tuple[list[str], Deferred]]):
|
||||||
|
The fetch requests. Each entry consists of a list of event
|
||||||
|
ids to be fetched, and a deferred to be completed once the
|
||||||
|
events have been fetched.
|
||||||
|
|
||||||
|
"""
|
||||||
|
with Measure(self._clock, "_fetch_event_list"):
|
||||||
try:
|
try:
|
||||||
with self._event_fetch_lock:
|
|
||||||
event_list = self._event_fetch_list
|
|
||||||
self._event_fetch_list = []
|
|
||||||
|
|
||||||
if not event_list:
|
|
||||||
single_threaded = self.database_engine.single_threaded
|
|
||||||
if single_threaded or i > EVENT_QUEUE_ITERATIONS:
|
|
||||||
self._event_fetch_ongoing -= 1
|
|
||||||
return
|
|
||||||
else:
|
|
||||||
self._event_fetch_lock.wait(EVENT_QUEUE_TIMEOUT_S)
|
|
||||||
i += 1
|
|
||||||
continue
|
|
||||||
i = 0
|
|
||||||
|
|
||||||
event_id_lists = zip(*event_list)[0]
|
event_id_lists = zip(*event_list)[0]
|
||||||
event_ids = [
|
event_ids = [
|
||||||
item for sublist in event_id_lists for item in sublist
|
item for sublist in event_id_lists for item in sublist
|
||||||
|
@ -280,9 +294,8 @@ class EventsWorkerStore(SQLBaseStore):
|
||||||
with PreserveLoggingContext():
|
with PreserveLoggingContext():
|
||||||
d.errback(e)
|
d.errback(e)
|
||||||
|
|
||||||
if event_list:
|
with PreserveLoggingContext():
|
||||||
with PreserveLoggingContext():
|
self.hs.get_reactor().callFromThread(fire, event_list)
|
||||||
self.hs.get_reactor().callFromThread(fire, event_list)
|
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def _enqueue_events(self, events, check_redacted=True, allow_rejected=False):
|
def _enqueue_events(self, events, check_redacted=True, allow_rejected=False):
|
||||||
|
|
Loading…
Reference in a new issue