-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Prevent large ephemeral event traffic to appservices upon startup #10836
Comments
After some investigation by Scott Weber and myself, it appears that only the most recent 100 read receipts will be sent to the appservice: synapse/synapse/handlers/receipts.py Lines 236 to 266 in a3a7514
In contrast, presence events don't appear to be bounded. When a new presence update occurs, that event and the users that may potentially be interested in it are passed to Lines 408 to 468 in ac22650
A few levels down, synapse/synapse/handlers/appservice.py Lines 341 to 386 in 89fe879
At this point, a few things happen:
There's a couple problems with this process:
|
@turt2live notes that normal events can come in large bursts as well when an appservice has been offline. |
@Half-Shot mentioned that upon start up, Synapse will send all missed ephemeral events to application services that have opted into receiving them (see MSC2409). There are some performance issues present with the feature's implementation in a couple of different circumstances.
Some background: a "stream token" is an incrementing integer. Every occurrence (a new typing event, a new read receipt, etc.) gets one of these IDs, and they're (usually rigidly) ordered in this way. Thus we can simply keep track of the last successfully sent stream token per app service to know what the AS needs to still receive.
synapse/synapse/storage/databases/main/appservice.py
Lines 387 to 412 in bdfde6d
When it comes time to send out the ephemeral events the appservice has missed, Synapse will send all read receipts and presence updates that it knows about and that are relevant to the namespaces the appservice has registered:
synapse/synapse/handlers/appservice.py
Lines 266 to 273 in a8a27b2
This historical data isn't very useful to the appservice as it has just been registered.
I'd be tempted to implement a time bound to the EDUs we send to appservices, such that very old EDUs are no longer considered.
Fixing both of these would help reduce the large amount of EDUs that can be sent to and overload both the appservice and Synapse itself when it tries to pull all of that information out of the database.
Finally, note that the above problems only seem to apply to the implementation of read receipts and presence events. Historical typing events are flat out not sent to appservices:
synapse/synapse/handlers/appservice.py
Line 235 in a8a27b2
The text was updated successfully, but these errors were encountered: