Skip to content

Commit

Permalink
Reduce pauses on large device list changes (#17192)
Browse files Browse the repository at this point in the history
For large accounts waking up all the relevant notifier streams can cause
pauses of the reactor.
  • Loading branch information
erikjohnston authored May 14, 2024
1 parent 0b91ccc commit ebe7738
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelog.d/17192.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve performance by fixing a reactor pause.
13 changes: 10 additions & 3 deletions synapse/replication/tcp/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
)
from synapse.types import PersistedEventPosition, ReadReceipt, StreamKeyType, UserID
from synapse.util.async_helpers import Linearizer, timeout_deferred
from synapse.util.iterutils import batch_iter
from synapse.util.metrics import Measure

if TYPE_CHECKING:
Expand Down Expand Up @@ -150,9 +151,15 @@ async def on_rdata(
if row.entity.startswith("@") and not row.is_signature:
room_ids = await self.store.get_rooms_for_user(row.entity)
all_room_ids.update(room_ids)
self.notifier.on_new_event(
StreamKeyType.DEVICE_LIST, token, rooms=all_room_ids
)

# `all_room_ids` can be large, so let's wake up those streams in batches
for batched_room_ids in batch_iter(all_room_ids, 100):
self.notifier.on_new_event(
StreamKeyType.DEVICE_LIST, token, rooms=batched_room_ids
)

# Yield to reactor so that we don't block.
await self._clock.sleep(0)
elif stream_name == PushersStream.NAME:
for row in rows:
if row.deleted:
Expand Down

0 comments on commit ebe7738

Please sign in to comment.