-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
caching on have_seen_event
is somewhat broken
#13865
Comments
We suspect this has been the case ever since the cache was added to Fixing this probably involves updating |
Relatedly: |
(Fortunately, |
I think that the usage of synapse/synapse/storage/databases/main/events_worker.py Lines 1485 to 1488 in cfe486b
I think that should actually be: @cachedList(cached_method_name="have_seen_event", list_name="event_ids")
async def _have_seen_events_dict(
self, room_id: str, event_ids: Collection[str],
) -> Dict[str, bool]: |
oh right, that's quite a lot easier. |
As mentioned by @erikjohnston, #13865 (comment)
Fix #13856 Fix #13865 > Discovered while trying to make Synapse fast enough for [this MSC2716 test for importing many batches](matrix-org/complement#214 (comment)). As an example, disabling the `have_seen_event` cache saves 10 seconds for each `/messages` request in that MSC2716 Complement test because we're not making as many federation requests for `/state` (speeding up `have_seen_event` itself is related to #13625) > > But this will also make `/messages` faster in general so we can include it in the [faster `/messages` milestone](https://github.com/matrix-org/synapse/milestone/11). > > *-- #13856 ### The problem `_invalidate_caches_for_event` doesn't run in monolith mode which means we never even tried to clear the `have_seen_event` and other caches. And even in worker mode, it only runs on the workers, not the master (AFAICT). Additionally there was bug with the key being wrong so `_invalidate_caches_for_event` never invalidates the `have_seen_event` cache even when it does run. Because we were using the `@cachedList` wrong, it was putting items in the cache under keys like `((room_id, event_id),)` with a `set` in a `set` (ex. `(('!TnCIJPKzdQdUlIyXdQ:test', '$Iu0eqEBN7qcyF1S9B3oNB3I91v2o5YOgRNPwi_78s-k'),)`) and we we're trying to invalidate with just `(room_id, event_id)` which did nothing.
As discovered in #13863 (comment) and discussed in #synapse-dev. Part of #13856
The cache on
have_seen_event
uses aTreeCache
, which means the cache is structured as{room_id: {event_id: result}}
. However,_have_seen_events_dict
tries to use it with@cachedList
, which stores entries as{(room_id, event_id): result}
. As a result, caching is inefficient, and cache invalidation is unreliable.The text was updated successfully, but these errors were encountered: