summary refs log tree commit diff
path: root/synapse/storage
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2015-05-21 11:18:22 +0100
committerErik Johnston <erik@matrix.org>2015-05-21 11:19:04 +0100
commit80a167b1f032ae9bcb75bdb20c2112a779dda516 (patch)
tree575ce8d2e747276bb9c74b4fb4d0c085d73c9fba /synapse/storage
parentSplit up _get_events into defer and txn versions (diff)
downloadsynapse-80a167b1f032ae9bcb75bdb20c2112a779dda516.tar.xz
Add comments
Diffstat (limited to '')
-rw-r--r--synapse/storage/events.py17
1 files changed, 14 insertions, 3 deletions
diff --git a/synapse/storage/events.py b/synapse/storage/events.py
index 656e57b5c6..3d798f5fa2 100644
--- a/synapse/storage/events.py
+++ b/synapse/storage/events.py
@@ -35,6 +35,16 @@ import simplejson as json
 logger = logging.getLogger(__name__)
 
 
+# These values are used in the `enqueus_event` and `_do_fetch` methods to
+# control how we batch/bulk fetch events from the database.
+# The values are plucked out of thing air to make initial sync run faster
+# on jki.re
+# TODO: Make these configurable.
+EVENT_QUEUE_THREADS = 3  # Max number of threads that will fetch events
+EVENT_QUEUE_ITERATIONS = 3  # No. times we block waiting for events
+EVENT_QUEUE_TIMEOUT_S = 0.1  # Timeout when waiting for events
+
+
 class EventsStore(SQLBaseStore):
     @defer.inlineCallbacks
     @log_function
@@ -518,11 +528,12 @@ class EventsStore(SQLBaseStore):
                     self._event_fetch_list = []
 
                     if not event_list:
-                        if self.database_engine.single_threaded or i > 3:
+                        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(0.1)
+                            self._event_fetch_lock.wait(EVENT_QUEUE_TIMEOUT_S)
                             i += 1
                             continue
                     i = 0
@@ -584,7 +595,7 @@ class EventsStore(SQLBaseStore):
 
             self._event_fetch_lock.notify()
 
-            if self._event_fetch_ongoing < 3:
+            if self._event_fetch_ongoing < EVENT_QUEUE_THREADS:
                 self._event_fetch_ongoing += 1
                 should_start = True
             else: