-
Notifications
You must be signed in to change notification settings - Fork 396
Fix performance regression related to delayed events processing #18926
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This is preferable to pulling out entire events and only fetching the `sender` field.
We also only call it once for all events in the batch, instead of per state delta.
There's no need to do this for every event in the batch. Just find the min time for all delayed events.
There are zero delayed events on matrix.org's database. We can save a lot of time pulling out state deltas by first just checking if there are any delayed events to actually deal with.
Initial theory is that the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't look at whether this is a good solution holistically with the delayed events feature. But the change itself looks like an improvement to what was there before.
13fd4bd
to
4ff8184
Compare
This reverts commit 9f1c7e3. This change caused delayed events to not be scheduled, thus in turn causing the `TestDelayedEvents/delayed_.*_events_are_sent_on_timeout` tests to fail. I don't fully understand why my change didn't work, but have spent enough time looking at the code. The optimisation was very slight anyhow, so I don't think it's worth persuing for longer.
1500d26
to
1eb25f1
Compare
Apply the same fix to a similar loop in the presence handling code.
If a room has been purged, then the associated event would be gone as well. Thus we wouldn't be able to pull out the sender. This is different from the `sender` field being null on an event.
synapse/handlers/delayed_events.py
Outdated
if sender_str is sentinel: | ||
# This can happen if a room is purged. State deltas related to | ||
# the room are left behind, but the event/room no longer exist. | ||
logger.warning( | ||
"Skipping state delta with event ID '%s' as it is an unknown event - the room may have been purged", | ||
delta.event_id, | ||
) | ||
continue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was added after an exception was found when running an earlier draft of this PR on element.io.
CI failures are due to flakes. |
Hopefully fixes #18925.
Carries out a number of optimisations to this bit of the codebase (note that on element.io we have about 7mil state deltas to process):
get_event
DB query per state delta with a single, smaller query for all state deltas.Set the next "scheduled at" time to the minimum of all delayed events once, instead of doing so for every delta.this ended up causing tests to fail, and has been reverted.Highly recommended to review commit-by-commit.
Pull Request Checklist
EventStore
toEventWorkerStore
.".code blocks
.