summary refs log tree commit diff
path: root/synapse
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2021-09-03 18:23:46 +0100
committerGitHub <noreply@github.com>2021-09-03 18:23:46 +0100
commit92b6ac31b22fd2fafc5a68602357212fd87b0607 (patch)
tree0c81066ed9ecd6d390bfefb291f4d7b45848fdde /synapse
parentAdd a partial index to `presence_stream` to speed up startups (#10748) (diff)
downloadsynapse-92b6ac31b22fd2fafc5a68602357212fd87b0607.tar.xz
Speed up MultiWriterIdGenerator when lots of IDs are in flight. (#10755)
Diffstat (limited to 'synapse')
-rw-r--r--synapse/storage/util/id_generators.py5
1 files changed, 3 insertions, 2 deletions
diff --git a/synapse/storage/util/id_generators.py b/synapse/storage/util/id_generators.py
index c768fdea56..6f7cbe40f4 100644
--- a/synapse/storage/util/id_generators.py
+++ b/synapse/storage/util/id_generators.py
@@ -19,6 +19,7 @@ from contextlib import contextmanager
 from typing import Dict, Iterable, List, Optional, Set, Tuple, Union
 
 import attr
+from sortedcontainers import SortedSet
 
 from synapse.metrics.background_process_metrics import run_as_background_process
 from synapse.storage.database import DatabasePool, LoggingTransaction
@@ -240,7 +241,7 @@ class MultiWriterIdGenerator:
 
         # Set of local IDs that we're still processing. The current position
         # should be less than the minimum of this set (if not empty).
-        self._unfinished_ids: Set[int] = set()
+        self._unfinished_ids: SortedSet[int] = SortedSet()
 
         # Set of local IDs that we've processed that are larger than the current
         # position, due to there being smaller unpersisted IDs.
@@ -473,7 +474,7 @@ class MultiWriterIdGenerator:
 
                 finished = set()
 
-                min_unfinshed = min(self._unfinished_ids)
+                min_unfinshed = self._unfinished_ids[0]
                 for s in self._finished_ids:
                     if s < min_unfinshed:
                         if new_cur is None or new_cur < s: