summary refs log tree commit diff
path: root/synapse/util/caches (follow)
Commit message (Collapse)AuthorAgeFilesLines
* Add optimisation to `StreamChangeCache` (#17130)Erik Johnston2024-05-061-1/+19
| | | | | | | When there have been lots of changes compared with the number of entities, we can do a fast(er) path. Locally I ran some benchmarking, and the comparison seems to give the best determination of which method we use.
* Fix bug where `StreamChangeCache` would not respect cache factors (#17152)Erik Johnston2024-05-031-1/+1
| | | Annoyingly mypy didn't pick up this typo.
* Bump mypy from 1.5.1 to 1.8.0 (#16901)dependabot[bot]2024-03-132-2/+2
|
* Bump black from 23.10.1 to 24.2.0 (#16936)dependabot[bot]2024-03-132-16/+8
|
* Don't invalidate the entire event cache when we purge history (#16905)Erik Johnston2024-02-131-0/+59
| | | | | We do this by adding support to the LRU cache for "extra indices" based on the cached value. This allows us to efficiently map from room ID to the cached events and only invalidate those.
* Correctly mention previous copyright (#16820)Erik Johnston2024-01-2311-0/+13
| | | | | During the migration the automated script to update the copyright headers accidentally got rid of some of the existing copyright lines. Reinstate them.
* Update license headersPatrick Cloke2023-11-2111-114/+176
|
* mypy plugin to check `@cached` return types (#14911)David Robertson2023-10-021-9/+55
| | | | | | | | Co-authored-by: David Robertson <davidr@element.io> Co-authored-by: Patrick Cloke <patrickc@matrix.org> Co-authored-by: Erik Johnston <erik@matrix.org> Assert that the return type of callables wrapped in @cached and @cachedList are cachable (aka immutable).
* Only use literal strings for process names (#16315)Erik Johnston2023-09-151-3/+1
|
* Improve type hints for attrs classes (#16276)David Robertson2023-09-083-19/+21
|
* Merge remote-tracking branch 'origin/release-v1.91' into release-v1.92Patrick Cloke2023-09-061-22/+0
|\
| * Revert MSC3861 introspection cache, admin impersonation and account lock ↵Quentin Gliech2023-09-061-22/+0
| | | | | | | | (#16258)
* | Fix typechecking with twisted trunk (#16121)David Robertson2023-08-241-1/+1
|/
* Add an admin endpoint to allow authorizing server to signal token ↵Shay2023-08-221-0/+22
| | | | revocations (#16125)
* Add metrics tracking for eviction to ResponseCache (#16028)Jason Little2023-08-011-2/+8
| | | | Track whether the ResponseCache is evicting due to invalidation or due to time.
* Prefill events after invalidate not before when persisting events (#15758)Jason Little2023-06-141-1/+7
| | | | | Fixes #15757
* Clear event caches when we purge history (#15609)Erik Johnston2023-06-081-1/+1
| | | | | | | This should help a little with #13476 --------- Co-authored-by: Patrick Cloke <patrickc@matrix.org>
* Add stricter mypy options (#15694)Patrick Cloke2023-05-311-4/+2
| | | | Enable warn_unused_configs, strict_concatenate, disallow_subclassing_any, and disallow_incomplete_defs.
* Improve type hints for cached decorator. (#15658)Patrick Cloke2023-05-241-2/+4
| | | | | The cached decorators always return a Deferred, which was not properly propagated. It was close enough when wrapping coroutines, but failed if a bare function was wrapped.
* Bump black from 22.12.0 to 23.1.0 (#15103)dependabot[bot]2023-02-221-1/+0
|
* Add missing type hints to tests.config. (#14681)Patrick Cloke2022-12-161-7/+2
|
* Improve type annotations for the helper methods on a `CachedFunction`. (#14685)reivilibre2022-12-161-3/+3
|
* Make `handle_new_client_event` throws `PartialStateConflictError` (#14665)Mathieu Velten2022-12-151-4/+10
| | | | | | | Then adapts calling code to retry when needed so it doesn't 500 to clients. Signed-off-by: Mathieu Velten <mathieuv@matrix.org> Co-authored-by: Sean Quah <8349537+squahtx@users.noreply.github.com>
* Check the stream position before checking if the cache is empty. (#14639)Patrick Cloke2022-12-081-4/+5
| | | | | | An empty cache does not mean the entity has no changed, if it is earlier than the earliest known stream position return that the entity *has* changed since the cache cannot accurately answer that query.
* Better return type for `get_all_entities_changed` (#14604)Erik Johnston2022-12-051-15/+37
| | | | Help callers from using the return value incorrectly by ensuring that callers explicitly check if there was a cache hit or not.
* Compare to the earliest known stream pos in the stream change cache. (#14435)Patrick Cloke2022-12-051-26/+116
| | | | | | The internal methods of the StreamChangeCache were inconsistently treating the earliest known stream position as valid. It is now treated as invalid, meaning the cache cannot determine if an entity at the earliest known stream position has changed or not.
* Batch fetch bundled annotations (#14491)Patrick Cloke2022-11-221-1/+1
| | | | | | | | Avoid an n+1 query problem and fetch the bundled aggregations for m.annotation relations in a single query instead of a query per event. This applies similar logic for as was previously done for edits in 8b309adb436c162510ed1402f33b8741d71fc058 (#11660) and threads in b65acead428653b988351ae8d7b22127a22039cd (#11752).
* Remove redundant types from comments. (#14412)Patrick Cloke2022-11-165-11/+12
| | | | | | | Remove type hints from comments which have been added as Python type hints. This helps avoid drift between comments and reality, as well as removing redundant information. Also adds some missing type hints which were simple to fill in.
* Remove duplicated code to evict entries. (#14410)Patrick Cloke2022-11-101-9/+2
| | | | | | | | This code was factored out to a method, but also left in-place. Calling this twice in a row makes no sense: the first call will reduce the size appropriately, but the loop will immediately exit since the cache size was already reduced.
* Remove unused `@lru_cache` decorator (#13595)Nick Mills-Barrett2022-10-251-104/+0
| | | | | | | * Remove unused `@lru_cache` decorator Spotted this working on something else. Co-authored-by: David Robertson <davidr@element.io>
* Bump flake8-bugbear from 21.3.2 to 22.9.23 (#14042)dependabot[bot]2022-10-192-3/+3
| | | | | Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Erik Johnston <erik@matrix.org> Co-authored-by: David Robertson <davidr@element.io>
* Fix `have_seen_event` cache not being invalidated (#13863)Eric Eastwood2022-09-271-0/+6
| | | | | | | | | | | | | | | | | | | | | Fix https://github.com/matrix-org/synapse/issues/13856 Fix https://github.com/matrix-org/synapse/issues/13865 > Discovered while trying to make Synapse fast enough for [this MSC2716 test for importing many batches](https://github.com/matrix-org/complement/pull/214#discussion_r741678240). 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 https://github.com/matrix-org/synapse/issues/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). > > *-- https://github.com/matrix-org/synapse/issues/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.
* Add cache invalidation across workers to module API (#13667)Mathieu Velten2022-09-211-7/+7
| | | Signed-off-by: Mathieu Velten <mathieuv@matrix.org>
* Fix a memory leak when running the unit tests. (#13798)reivilibre2022-09-141-1/+2
|
* Fix cache metrics not being updated when not using the legacy exposition ↵reivilibre2022-09-081-12/+48
| | | | module. (#13717)
* Update Grafana dashboard to not use legacy metric names. (#13714)reivilibre2022-09-061-2/+2
|
* Add experimental configuration option to allow disabling legacy Prometheus ↵reivilibre2022-08-241-8/+8
| | | | | metric names. (#13540) Co-authored-by: David Robertson <davidr@element.io>
* Speed up `@cachedList` (#13591)Erik Johnston2022-08-233-141/+297
| | | | | | | | | This speeds things up by ~2x. The vast majority of the time is now spent in `LruCache` moving things around the linked lists. We do this via two things: 1. Don't create a deferred per-key during bulk set operations in `DeferredCache`. Instead, only create them if a subsequent caller asks for the key. 2. Add a bulk lookup API to `DeferredCache` rather than use a loop.
* Cache user IDs instead of profile objects (#13573)Nick Mills-Barrett2022-08-231-7/+19
| | | The profile objects are never used and increase cache size significantly.
* Optimise async get event lookups (#13435)Nick Mills-Barrett2022-08-041-0/+17
| | | | | | Still maintains local in memory lookup optimisation, but does any external lookup as part of the deferred that prevents duplicate lookups for the same event at once. This makes the assumption that fetching from an external cache is a non-zero load operation.
* Make DictionaryCache have better expiry properties (#13292)Erik Johnston2022-07-213-33/+313
|
* Async get event cache prep (#13242)Nick Mills-Barrett2022-07-151-0/+38
| | | | | Some experimental prep work to enable external event caching based on #9379 & #12955. Doesn't actually move the cache at all, just lays the groundwork for async implemented caches. Signed off by Nick @ Beeper (@Fizzadar)
* Type `tests.utils` (#13028)David Robertson2022-07-051-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Cast to postgres types when handling postgres db * Remove unused method * Easy annotations * Annotate create_room * Use `ParamSpec` to annotate looping_call * Annotate `default_config` * Track `now` as a float `time_ms` returns an int like the proper Synapse `Clock` * Introduce a `Timer` dataclass * Introduce a Looper type * Suppress checking of a mock * tests.utils is typed * Changelog * Whoops, import ParamSpec from typing_extensions * ditch the psycopg2 casts
* Fix caching behavior for relations push rules. (#12859)Patrick Cloke2022-05-251-7/+8
| | | | | By always returning all requested values from the function wrapped by cachedList. Otherwise implicit None values get added into the cache, which are unexpected.
* Add config flags to allow for cache auto-tuning (#12701)Shay2022-05-131-10/+69
|
* Remove unused `# type: ignore`s (#12531)David Robertson2022-04-271-1/+1
| | | | | | | | | | | | | | | | | | | | | | Over time we've begun to use newer versions of mypy, typeshed, stub packages---and of course we've improved our own annotations. This makes some type ignore comments no longer necessary. I have removed them. There was one exception: a module that imports `select.epoll`. The ignore is redundant on Linux, but I've kept it ignored for those of us who work on the source tree using not-Linux. (#11771) I'm more interested in the config line which enforces this. I want unused ignores to be reported, because I think it's useful feedback when annotating to know when you've fixed a problem you had to previously ignore. * Installing extras before typechecking Lacking an easy way to install all extras generically, let's bite the bullet and make install the hand-maintained `all` extra before typechecking. Now that https://github.com/matrix-org/backend-meta/pull/6 is merged to the release/v1 branch.
* Add more type hints to the main state store. (#12267)Patrick Cloke2022-03-311-2/+4
|
* Add cancellation support to `@cached` and `@cachedList` decorators (#12183)Sean Quah2022-03-141-0/+11
| | | | | | | | These decorators mostly support cancellation already. Add cancellation tests and fix use of finished logging contexts by delaying cancellation, as suggested by @erikjohnston. Signed-off-by: Sean Quah <seanq@element.io>
* Remove unnecessary pass statements. (#12206)Patrick Cloke2022-03-111-2/+0
|
* Allow for ignoring some arguments when caching. (#12189)Patrick Cloke2022-03-091-16/+58
| | | | | * `@cached` can now take an `uncached_args` which is an iterable of names to not use in the cache key. * Requires `@cached`, @cachedList` and `@lru_cache` to use keyword arguments for clarity. * Asserts that keyword-only arguments in cached functions are not accepted. (I tested this briefly and I don't believe this works properly.)
* Fix 'Unhandled error in Deferred' (#12089)Richard van der Hoff2022-03-011-32/+32
| | | | | | | | | | | | | * Fix 'Unhandled error in Deferred' Fixes a CRITICAL "Unhandled error in Deferred" log message which happened when a function wrapped with `@cachedList` failed * Minor optimisation to cachedListDescriptor we can avoid re-using `missing`, which saves looking up entries in `deferreds_map`, and means we don't need to copy it. * Improve type annotation on CachedListDescriptor
* Track cache invalidations (#12000)Erik Johnston2022-02-153-1/+9
| | | Currently we only track evictions due to size or time constraints.
* Describe `prune_unread_entries` in docstrings (#11876)David Robertson2022-02-023-2/+17
| | | Should have been caught in #10826.
* Use auto_attribs/native type hints for attrs classes. (#11692)Patrick Cloke2022-01-131-6/+5
|
* Update to the current version of Black and run it on Synapse codebase (#11596)Shay2021-12-231-1/+0
| | | | | | | | | * update black version * run updated version of black on code * newsfragment * enumerate python versions
* Improve opentracing support for `ResponseCache` (#11607)Richard van der Hoff2021-12-201-35/+92
| | | This adds some opentracing annotations to ResponseCache, to make it easier to see what's going on; in particular, it adds a link back to the initial trace which is actually doing the work of generating the response.
* Add missing type hints to `synapse.logging.context` (#11556)Sean Quah2021-12-141-0/+1
|
* Fix `LruCache` corruption bug with a `size_callback` that can return 0 (#11454)Sean Quah2021-11-301-1/+4
| | | | | | | | | | | When all entries in an `LruCache` have a size of 0 according to the provided `size_callback`, and `drop_from_cache` is called on a cache node, the node would be unlinked from the LRU linked list but remain in the cache dictionary. An assertion would be later be tripped due to the inconsistency. Avoid unintentionally calling `__len__` and use a strict `is None` check instead when unwrapping the weak reference.
* Eliminate a few `Any`s in `LruCache` type hints (#11453)Sean Quah2021-11-302-17/+29
|
* Add type annotations to `synapse.metrics` (#10847)Sean Quah2021-11-171-1/+1
|
* Add most missing type hints to synapse.util (#11328)Patrick Cloke2021-11-164-45/+66
|
* More types for synapse.util, part 1 (#10888)David Robertson2021-10-066-49/+45
| | | | | | | | | | | | | | The following modules now pass `disallow_untyped_defs`: * synapse.util.caches.cached_call * synapse.util.caches.lrucache * synapse.util.caches.response_cache * synapse.util.caches.stream_change_cache * synapse.util.caches.ttlcache pass * synapse.util.daemonize * synapse.util.patch_inline_callbacks pass `no-untyped-defs` * synapse.util.versionstring Additional typing in synapse.util.metrics. Didn't get this to pass `no-untyped-defs`, think I'll need to watch #10847
* Opt out of cache expiry for `get_users_who_share_room_with_user` (#10826)David Robertson2021-09-223-3/+20
| | | | * Allow LruCaches to opt out of time-based expiry * Don't expire `get_users_who_share_room` & friends
* Track why we're evicting from caches (#10829)David Robertson2021-09-223-15/+30
| | | So we can see distinguish between "evicting because the cache is too big" and "evicting because the cache entries haven't been recently used".
* Add type hints to state database module. (#10823)Patrick Cloke2021-09-151-2/+2
|
* Add types to synapse.util. (#10601)reivilibre2021-09-106-35/+40
|
* Fix up type hints for Twisted 21.7 (#10490)Richard van der Hoff2021-07-282-4/+13
| | | Mostly this involves decorating a few Deferred declarations with extra type hints. We wrap the types in quotes to avoid runtime errors when running against older versions of Twisted that don't have generics on Deferred.
* improve typing annotations in CachedCall (#10450)Richard van der Hoff2021-07-281-10/+17
| | | | | tighten up some of the typing in CachedCall, which is going to be needed when Twisted 21.7 brings better typing on Deferred.
* [pyupgrade] `synapse/` (#10348)Jonathan de Jong2021-07-192-4/+2
| | | | | | | | | This PR is tantamount to running ``` pyupgrade --py36-plus --keep-percent-format `find synapse/ -type f -name "*.py"` ``` Part of #9744
* Use inline type hints in `http/federation/`, `storage/` and `util/` (#10381)Jonathan de Jong2021-07-1510-45/+45
|
* Add support for evicting cache entries based on last access time. (#10205)Erik Johnston2021-07-051-35/+202
|
* Extend `ResponseCache` to pass a context object into the callback (#10157)Richard van der Hoff2021-06-141-26/+73
| | | | | This is the first of two PRs which seek to address #8518. This first PR lays the groundwork by extending ResponseCache; a second PR (#10158) will update the SyncHandler to actually use it, and fix the bug. The idea here is that we allow the callback given to ResponseCache.wrap to decide whether its result should be cached or not. We do that by (optionally) passing a ResponseCacheContext into it, which it can modify.
* Combine `LruCache.invalidate` and `invalidate_many` (#9973)Richard van der Hoff2021-05-274-35/+36
| | | | | | | | | | * Make `invalidate` and `invalidate_many` do the same thing ... so that we can do either over the invalidation replication stream, and also because they always confused me a bit. * Kill off `invalidate_many` * changelog
* Remove `keylen` from `LruCache`. (#9993)Richard van der Hoff2021-05-244-47/+70
| | | | | | | `keylen` seems to be a thing that is frequently incorrectly set, and we don't really need it. The only time it was used was to figure out if we had removed a subtree in `del_multi`, which we can do better by changing `TreeCache.pop` to return a different type (`TreeCacheNode`). Commits should be independently reviewable.
* Minor `@cachedList` enhancements (#9975)Richard van der Hoff2021-05-141-6/+8
| | | | | | - use a tuple rather than a list for the iterable that is passed into the wrapped function, for performance - test that we can pass an iterable and that keys are correctly deduped.
* Optionally track memory usage of each LruCache (#9881)Erik Johnston2021-05-052-1/+78
| | | | | This will double count slightly in the presence of interned strings. It's off by default as it can consume a lot of resources.
* Reduce memory footprint of caches (#9886)Erik Johnston2021-04-281-18/+59
|
* Remove various bits of compatibility code for Python <3.6 (#9879)Andrew Morgan2021-04-271-1/+1
| | | I went through and removed a bunch of cruft that was lying around for compatibility with old Python versions. This PR also will now prevent Synapse from starting unless you're running Python 3.6+.
* Remove `synapse.types.Collection` (#9856)Richard van der Hoff2021-04-221-2/+1
| | | This is no longer required, since we have dropped support for Python 3.5.
* Remove redundant "coding: utf-8" lines (#9786)Jonathan de Jong2021-04-1410-10/+0
| | | | | | | Part of #9744 Removes all redundant `# -*- coding: utf-8 -*-` lines from files, as python 3 automatically reads source code as utf-8 now. `Signed-off-by: Jonathan de Jong <jonathan@automatia.nl>`
* Bugbear: Add Mutable Parameter fixes (#9682)Jonathan de Jong2021-04-081-6/+8
| | | | | | | Part of #9366 Adds in fixes for B006 and B008, both relating to mutable parameter lint errors. Signed-off-by: Jonathan de Jong <jonathan@automatia.nl>
* Add type hints to expiring cache. (#9730)Patrick Cloke2021-04-061-32/+51
|
* Update mypy configuration: `no_implicit_optional = True` (#9742)Jonathan de Jong2021-04-051-1/+3
|
* Add type hints to DictionaryCache and TTLCache. (#9442)Patrick Cloke2021-03-292-44/+73
|
* Make it possible to use dmypy (#9692)Erik Johnston2021-03-261-2/+2
| | | | | | | | | Running `dmypy run` will do a `mypy` check while spinning up a daemon that makes rerunning `dmypy run` a lot faster. `dmypy` doesn't support `follow_imports = silent` and has `local_partial_types` enabled, so this PR enables those options and fixes the issues that were newly raised. Note that `local_partial_types` will be enabled by default in upcoming mypy releases.
* Enable addtional flake8-bugbear linting checks. (#9659)Jonathan de Jong2021-03-241-1/+1
|
* Add ResponseCache tests. (#9458)Jonathan de Jong2021-03-081-6/+4
|
* Revert "Fix #8518 (sync requests being cached wrongly on timeout) (#9358)"Patrick Cloke2021-03-021-32/+2
| | | | | | | This reverts commit f5c93fc9931e4029bbd8000f398b6f39d67a8c46. This is being backed out due to a regression (#9507) and additional review feedback being provided.
* Fix #8518 (sync requests being cached wrongly on timeout) (#9358)Jonathan de Jong2021-02-241-2/+32
| | | | | | | This fixes #8518 by adding a conditional check on `SyncResult` in a function when `prev_stream_token == current_stream_token`, as a sanity check. In `CachedResponse.set.<remove>()`, the result is immediately popped from the cache if the conditional function returns "false". This prevents the caching of a timed-out `SyncResult` (that has `next_key` as the stream key that produced that `SyncResult`). The cache is prevented from returning a `SyncResult` that makes the client request the same stream key over and over again, effectively making it stuck in a loop of requesting and getting a response immediately for as long as the cache keeps those values. Signed-off-by: Jonathan de Jong <jonathan@automatia.nl>
* Update black, and run auto formatting over the codebase (#9381)Eric Eastwood2021-02-163-13/+16
| | | | | | | - Update black version to the latest - Run black auto formatting over the codebase - Run autoformatting according to [`docs/code_style.md `](https://github.com/matrix-org/synapse/blob/80d6dc9783aa80886a133756028984dbf8920168/docs/code_style.md) - Update `code_style.md` docs around installing black to use the correct version
* Clean up caching/locking of OIDC metadata load (#9362)Richard van der Hoff2021-02-161-0/+129
| | | | Ensure that we lock correctly to prevent multiple concurrent metadata load requests, and generally clean up the way we construct the metadata cache.
* Empty iterables should count towards cache usage. (#9028)Patrick Cloke2021-01-061-1/+1
|
* Implement and use an @lru_cache decorator (#8595)Richard van der Hoff2020-10-301-47/+188
| | | We don't always need the full power of a DeferredCache.
* Optimise CacheDescriptor (#8594) github/release-v1.21.3 release-v1.21.3Richard van der Hoff2020-10-211-5/+7
| | | don't bother constricting a CacheContext unless we need one.
* fix failure caseRichard van der Hoff2020-10-211-1/+4
|
* optimise DeferredCache.setRichard van der Hoff2020-10-211-3/+12
|
* Push some deferred wrangling down into DeferredCacheRichard van der Hoff2020-10-212-34/+55
|
* Fix 'LruCache' object has no attribute '_on_resize' (#8591)Richard van der Hoff2020-10-191-1/+9
| | | We need to make sure we are readu for the `set_cache_factor` callback.
* Add `DeferredCache.get_immediate` method (#8568)Richard van der Hoff2020-10-191-10/+25
| | | | | | | | | | | * Add `DeferredCache.get_immediate` method A bunch of things that are currently calling `DeferredCache.get` are only really interested in the result if it's completed. We can optimise and simplify this case. * Remove unused 'default' parameter to DeferredCache.get() * another get_immediate instance
* Replace DeferredCache with LruCache where possible (#8563)Richard van der Hoff2020-10-191-0/+3
| | | Most of these uses don't need a full-blown DeferredCache; LruCache is lighter and more appropriate.
* review commentsRichard van der Hoff2020-10-161-3/+8
|
* Apply suggestions from code reviewRichard van der Hoff2020-10-161-1/+1
| | | Co-authored-by: Patrick Cloke <clokep@users.noreply.github.com>
* type annotations for LruCacheRichard van der Hoff2020-10-163-23/+77
|
* Make LruCache register its own metrics (#8561)Richard van der Hoff2020-10-164-54/+57
| | | | | rather than have everything that instantiates an LruCache manage metrics separately, have LruCache do it itself.
* Enable mypy for synapse.util.caches (#8547)Richard van der Hoff2020-10-151-1/+1
| | | This seemed to entail dragging in a type stub for SortedList.
* move DeferredCache into its own moduleRichard van der Hoff2020-10-142-282/+294
|
* Rename Cache->DeferredCacheRichard van der Hoff2020-10-141-7/+12
|
* Add some more type annotations to CacheRichard van der Hoff2020-10-142-23/+61
|
* Add type hints to response cache. (#8507)Patrick Cloke2020-10-091-22/+28
|
* Use slots in attrs classes where possible (#8296)Patrick Cloke2020-09-141-1/+1
| | | | | slots use less memory (and attribute access is faster) while slightly limiting the flexibility of the class attributes. This focuses on objects which are instantiated "often" and for short periods of time.
* Stop sub-classing object (#8249)Patrick Cloke2020-09-048-16/+16
|
* Fix typing for `@cached` wrapped functions (#8240)Erik Johnston2020-09-031-14/+28
| | | This requires adding a mypy plugin to fiddle with the type signatures a bit.
* Remove the unused inlineCallbacks code-paths in the caching code (#8119)Patrick Cloke2020-08-191-46/+8
|
* Remove unnecessary maybeDeferred calls (#8044)Patrick Cloke2020-08-071-1/+1
|
* Fix some spelling mistakes / typos. (#7811)Patrick Cloke2020-07-091-1/+1
|
* Replace all remaining six usage with native Python 3 equivalents (#7704)Dagfinn Ilmari Mannsåker2020-06-161-3/+1
|
* Replace iteritems/itervalues/iterkeys with native versions. (#7692)Patrick Cloke2020-06-153-10/+4
|
* Don't apply cache factor to event cache. (#7578)Erik Johnston2020-05-271-0/+4
| | | | This is already correctly done when we instansiate the cache, but wasn't when it got reloaded (which always happens at least once on startup).
* remove miscellaneous PY2 codeRichard van der Hoff2020-05-151-6/+1
|
* Allow configuration of Synapse's cache without using synctl or environment ↵Amber Brown2020-05-117-92/+206
| | | | variables (#6391)
* Speed up fetching device lists changes in sync.Erik Johnston2020-05-051-4/+15
| | | | | Currently we copy `users_who_share_room` needlessly about three times, which is expensive when the set is large (which it can easily be).
* Extend StreamChangeCache to support multiple entities per stream ID (#7303)Richard van der Hoff2020-04-221-46/+71
| | | | | | | | | | | | | | | | | | | First some background: StreamChangeCache is used to keep track of what "entities" have changed since a given stream ID. So for example, we might use it to keep track of when the last to-device message for a given user was received [1], and hence whether we need to pull any to-device messages from the database on a sync [2]. Now, it turns out that StreamChangeCache didn't support more than one thing being changed at a given stream_id (this was part of the problem with #7206). However, it's entirely valid to send to-device messages to more than one user at a time. As it turns out, this did in fact work, because *some* methods of StreamChangeCache coped ok with having multiple things changing on the same stream ID, and it seems we never actually use the methods which don't work on the stream change caches where we allow multiple changes at the same stream ID. But that feels horribly fragile, hence: let's update StreamChangeCache to properly support this, and add some typing and some more tests while we're at it. [1]: https://github.com/matrix-org/synapse/blob/release-v1.12.3/synapse/storage/data_stores/main/deviceinbox.py#L301 [2]: https://github.com/matrix-org/synapse/blob/release-v1.12.3/synapse/storage/data_stores/main/deviceinbox.py#L47-L51
* On catchup, process each row with its own stream id (#7286)Richard van der Hoff2020-04-201-0/+3
| | | | | | Other parts of the code (such as the StreamChangeCache) assume that there will not be multiple changes with the same stream id. This code was introduced in #7024, and I hope this fixes #7206.
* Reduce amount of logging at INFO level. (#6862)Erik Johnston2020-02-061-1/+1
| | | | | | | | A lot of the things we log at INFO are now a bit superfluous, so lets make them DEBUG logs to reduce the amount we log by default. Co-Authored-By: Brendan Abolivier <babolivier@matrix.org> Co-authored-by: Brendan Abolivier <github@brendanabolivier.com>
* look up cross-signing keys from the DB in bulk (#6486)Hubert Chathi2019-12-121-1/+1
|
* Remove SnapshotCache in favour of ResponseCacheErik Johnston2019-12-091-94/+0
|
* Fix LruCache callback deduplication (#6213)V024602019-11-071-11/+37
|
* Remove usage of deprecated logger.warn method from codebase (#6271)Andrew Morgan2019-10-311-1/+1
| | | Replace every instance of `logger.warn` with `logger.warning` as the former is deprecated.
* Update docstringErik Johnston2019-10-291-3/+2
|
* Quick fix to ensure cache descriptors always return deferredsErik Johnston2019-10-281-2/+2
|
* Fix up some typechecking (#6150)Amber Brown2019-10-023-4/+25
| | | | | | * type checking fixes * changelog
* Retry well-known lookup before expiry.Erik Johnston2019-08-131-3/+5
| | | | | | | | | This gives a bit of a grace period where we can attempt to refetch a remote `well-known`, while still using the cached result if that fails. Hopefully this will make the well-known resolution a bit more torelant of failures, rather than it immediately treating failures as "no result" and caching that for an hour.
* Fix some error cases in the caching layer. (#5749)Richard van der Hoff2019-07-251-32/+42
| | | | | | | There was some inconsistent behaviour in the caching layer around how exceptions were handled - particularly synchronously-thrown ones. This seems to be most easily handled by pushing the creation of ObservableDeferreds down from CacheDescriptor to the Cache.
* Add a prometheus metric for active cache lookups. (#5750)Richard van der Hoff2019-07-242-2/+33
| | | | | | * Add a prometheus metric for active cache lookups. * changelog
* Replace returnValue with return (#5736)Amber Brown2019-07-232-2/+2
|
* Move logging utilities out of the side drawer of util/ and into logging/ (#5606)Amber Brown2019-07-042-7/+8
|
* Prevent multiple upgrades on the same room at once (#5051)Andrew Morgan2019-06-251-1/+1
| | | | | | | Closes #4583 Does slightly less than #5045, which prevented a room from being upgraded multiple times, one after another. This PR still allows that, but just prevents two from happening at the same time. Mostly just to mitigate the fact that servers are slow and it can take a moment for the room upgrade to actually complete. We don't want people sending another request to upgrade the room when really they just thought the first didn't go through.
* Run Black. (#5482)Amber Brown2019-06-209-81/+109
|
* Add a caching layer to .well-known responses (#4516)Richard van der Hoff2019-01-301-0/+161
|
* Make scripts/ and scripts-dev/ pass pyflakes (and the rest of the codebase ↵Amber Brown2018-10-201-1/+3
| | | | on py3) (#4068)
* Correctly match 'dict.pop' apiErik Johnston2018-10-011-3/+11
|
* Don't update eviction metrics on explicit removalErik Johnston2018-10-011-5/+0
|
* Merge branch 'rav/fix_expiring_cache_len' into erikj/destination_retry_cacheRichard van der Hoff2018-09-261-10/+17
|\
| * Log which cache is throwing exceptionsRichard van der Hoff2018-09-261-10/+17
| |
| * Fix ExpiringCache.__len__ to be accurateErik Johnston2018-09-261-10/+7
| | | | | | | | | | | | | | | | | | | | | | | | It used to try and produce an estimate, which was sometimes negative. This caused metrics to be sad, so lets always just calculate it from scratch. (This appears to have been a longstanding bug, but one which has been made more of a problem by #3932 and #3933). (This was originally done by Erik as part of #3933. I'm cherry-picking it because really it's a fix in its own right)
* | Fix ExpiringCache.__len__ to be accurateErik Johnston2018-09-211-12/+9
| | | | | | | | | | | | It used to try and produce an estimate, which was sometimes negative. This caused metrics to be sad, so lets always just calculate it from scratch.
* | Add a five minute cache to get_destination_retry_timingsErik Johnston2018-09-211-0/+13
| | | | | | | | Hopefully helps with #3931
* | Make ExpiringCache slightly more performantErik Johnston2018-09-211-1/+5
|/
* Fix some instances of ExpiringCache not expiring cache itemsErik Johnston2018-09-211-1/+0
| | | | | | | | ExpiringCache required that `start()` be called before it would actually start expiring entries. A number of places didn't do that. This PR removes `start` from ExpiringCache, and automatically starts backround reaping process on creation instead.
* Rename async to async_helpers because `async` is a keyword on Python 3.7 (#3678)Amber Brown2018-08-103-3/+3
|
* fix invalidationRichard van der Hoff2018-07-271-1/+1
|
* Rewrite cache list decoratorRichard van der Hoff2018-07-271-67/+64
| | | | | Because it was complicated and annoyed me. I suspect this will be more efficient too.
* Fix some looping_call calls which were broken in #3604Richard van der Hoff2018-07-261-1/+1
| | | | | | | | | It turns out that looping_call does check the deferred returned by its callback, and (at least in the case of client_ips), we were relying on this, and I broke it in #3604. Update run_as_background_process to return the deferred, and make sure we return it to clock.looping_call.
* Run things as background processesRichard van der Hoff2018-07-181-1/+5
| | | | | | | | This fixes #3518, and ensures that we get useful logs and metrics for lots of things that happen in the background. (There are certainly more things that happen in the background; these are just the common ones I've found running a single-process synapse locally).
* Use efficient .intersectionErik Johnston2018-07-171-4/+1
|
* Fix perf regression in PR #3530Erik Johnston2018-07-171-1/+6
| | | | | | | | The get_entities_changed function was changed to return all changed entities since the given stream position, rather than only those changed from a given list of entities. This resulted in the function incorrectly returning large numbers of entities that, for example, caused large increases in database usage.
* Don't return unknown entities in get_entities_changedErik Johnston2018-07-131-8/+1
| | | | | | | | The stream cache keeps track of all entities that have changed since a particular stream position, so get_entities_changed does not need to return unknown entites when given a larger stream position. This makes it consistent with the behaviour of has_entity_changed.
* Reduce set building in get_entities_changedRichard van der Hoff2018-07-121-8/+12
| | | | | | | | | | | This line shows up as about 5% of cpu time on a synchrotron: not_known_entities = set(entities) - set(self._entity_to_key) Presumably the problem here is that _entity_to_key can be largeish, and building a set for its keys every time this function is called is slow. Here we rewrite the logic to avoid building so many sets.
* run isortAmber Brown2018-07-096-26/+23
|
* Revert "Revert "Try to not use as much CPU in the StreamChangeCache"" (#3454)Amber Brown2018-06-281-2/+4
|
* Revert "Try to not use as much CPU in the StreamChangeCache"Matthew Hodgson2018-06-261-4/+2
|
* fixesAmber Brown2018-06-261-2/+2
|
* fixesAmber Brown2018-06-261-2/+2
|
* try and make loading items from the cache fasterAmber Brown2018-06-261-2/+4
|
* Disable partial state group caching for wildcard lookupsRichard van der Hoff2018-06-221-13/+12
| | | | | | | When _get_state_for_groups is given a wildcard filter, just do a complete lookup. Hopefully this will give us the best of both worlds by not filling up the ram if we only need one or two keys, but also making the cache still work for the federation reader usecase.
* Port to sortedcontainers (with tests!) (#3332)Amber Brown2018-06-061-26/+31
|
* Add hacky cache factor override systemErik Johnston2018-06-042-2/+12
|
* Consistently use six's iteritems and wrap lazy keys/values in list() if ↵Amber Brown2018-05-312-3/+5
| | | | they're not meant to be lazy (#3307)
* Merge pull request #3281 from NotAFile/py3-six-isinstanceAmber Brown2018-05-301-4/+8
|\ | | | | remaining isintance fixes
| * remaining isintance fixesAdrian Tschira2018-05-241-4/+8
| | | | | | | | Signed-off-by: Adrian Tschira <nota@notafile.com>
* | add comment about why unregAmber Brown2018-05-281-0/+2
| |
* | Merge remote-tracking branch 'origin/develop' into 3218-official-promAmber Brown2018-05-281-1/+6
|\|
| * fix py3 intern and remove unnecessary py3 encodeAdrian Tschira2018-05-191-1/+6
| | | | | | | | Signed-off-by: Adrian Tschira <nota@notafile.com>
* | cleanup pep8 errorsAmber Brown2018-05-221-2/+5
| |
* | fixesAmber Brown2018-05-222-12/+30
| |
* | replacing portionsAmber Brown2018-05-216-27/+51
|/
* Merge pull request #3093 from matrix-org/rav/response_cache_wrapRichard van der Hoff2018-04-201-14/+74
|\ | | | | Refactor ResponseCache usage
| * ResponseCache: fix handling of completed resultsRichard van der Hoff2018-04-131-13/+19
| | | | | | | | | | Turns out that ObservableDeferred.observe doesn't return a deferred if the result is already completed. Fix handling and improve documentation.
| * Refactor ResponseCache usageRichard van der Hoff2018-04-121-2/+56
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Adds a `.wrap` method to ResponseCache which wraps up the boilerplate of a (get, set) pair, and then use it throughout the codebase. This will be largely non-functional, but does include the following functional changes: * federation_server.on_context_state_request: drops use of _server_linearizer which looked redundant and could cause incorrect cache misses by yielding between the get and the set. * RoomListHandler.get_remote_public_room_list(): fixes logcontext leaks * the wrap function includes some logging. I'm hoping this won't be too noisy on production.
* | Revert "Use sortedcontainers instead of blist"Richard van der Hoff2018-04-131-2/+2
|/ | | | | | | | | | | This reverts commit 9fbe70a7dc3afabfdac176ba1f4be32dd44602aa. It turns out that sortedcontainers.SortedDict is not an exact match for blist.sorteddict; in particular, `popitem()` removes things from the opposite end of the dict. This is trivial to fix, but I want to add some unit tests, and potentially some more thought about it, before we do so.
* Merge pull request #3092 from matrix-org/rav/response_cache_metricsRichard van der Hoff2018-04-121-1/+13
|\ | | | | Add metrics for ResponseCache
| * Add metrics for ResponseCacheRichard van der Hoff2018-04-101-1/+13
| |
* | Merge pull request #3059 from matrix-org/rav/doc_response_cacheRichard van der Hoff2018-04-121-0/+32
|\ \ | | | | | | Document the behaviour of ResponseCache
| * | Document the behaviour of ResponseCacheRichard van der Hoff2018-04-041-0/+32
| | | | | | | | | | | | | | | | | | it looks like everything that uses ResponseCache expects to have to `make_deferred_yieldable` its results. It's debatable whether that is the best approach, but let's document it for now to avoid further confusion.
* | | Use sortedcontainers instead of blistVincent Breitmoser2018-04-101-2/+2
| |/ |/| | | | | | | | | | | | | This commit drop-in replaces blist with SortedContainers. They are written in pure python so work with pypy, but perform as good as native implementations, at least in a couple benchmarks: http://www.grantjenks.com/docs/sortedcontainers/performance.html
* | Fix overzealous cache invalidationRichard van der Hoff2018-04-051-26/+38
|/ | | | | Fixes an issue where a cache invalidation would invalidate *all* pending entries, rather than just the entry that we intended to invalidate.
* Add commentsErik Johnston2018-03-191-0/+7
|
* Fix bug where state cache used lots of memoryErik Johnston2018-03-152-5/+9
| | | | | | | | | The state cache bases its size on the sum of the size of entries. The size of the entry is calculated once on insertion, so it is important that the size of entries does not change. The DictionaryCache modified the entries size, which caused the state cache to incorrectly think it was smaller than it actually was.
* report metrics on number of cache evictionsRichard van der Hoff2018-02-053-4/+34
|
* Increase default cache factor size.Erik Johnston2017-07-041-1/+1
|
* Define CACHE_SIZE_FACTOR onceErik Johnston2017-07-042-9/+2
|
* Use an ExpiringCache for storing registration sessionsErik Johnston2017-06-291-0/+3
| | | | | This is because pruning them was a significant performance drain on matrix.org
* Rewrite conditionalErik Johnston2017-06-091-1/+1
|
* Fix has_any_entity_changedErik Johnston2017-06-091-4/+4
| | | | | | | | Occaisonally has_any_entity_changed would throw the error: "Set changed size during iteration" when taking the max of the `sorteddict`. While its uncertain how that happens, its quite inefficient to iterate over the entire dict anyway so we change to using the more traditional `bisect_*` functions.
* Add stream change cacheErik Johnston2017-05-311-0/+15
|
* Pull out if statement from for loopErik Johnston2017-05-221-6/+14
|
* Update list cache to handle one arg caseErik Johnston2017-05-221-17/+33
| | | | | | We update the normal cache descriptors to handle caches with a single argument specially so that the key wasn't a 1-tuple. We need to update the cache list to be aware of this.
* Make get_state_groups_from_groups faster.Erik Johnston2017-05-171-11/+46
| | | | | | | | | Most of the time was spent copying a dict to filter out sentinel values that indicated that keys did not exist in the dict. The sentinel values were added to ensure that we cached the non-existence of keys. By updating DictionaryCache to keep track of which keys were known to not exist itself we can remove a dictionary copy.
* Don't update event cache hit ratio from get_joined_usersErik Johnston2017-05-081-3/+6
| | | | | Otherwise the hit ration of plain get_events gets completely skewed by calls to get_joined_users* functions.
* Optimise caches with single keyErik Johnston2017-05-041-9/+33
|
* Remove DEBUG_CACHESErik Johnston2017-04-251-2/+0
|
* Reduce cache size by not storing deferredsErik Johnston2017-04-251-18/+21
| | | | | | | | | | | | | | | | | | | | Currently the cache descriptors store deferreds rather than raw values, this is a simple way of triggering only one database hit and sharing the result if two callers attempt to get the same value. However, there are a few caches that simply store a mapping from string to string (or int). These caches can have a large number of entries, under the assumption that each entry is small. However, the size of a deferred (specifically the size of ObservableDeferred) is signigicantly larger than that of the raw value, 2kb vs 32b. This PR therefore changes the cache descriptors to store the raw values rather than the deferreds. As a side effect cached storage function now either return a deferred or the actual value, as the cached list decriptor already does. This is fine as we always end up just yield'ing on the returned value eventually, which handles that case correctly.
* Only intern ascii stringsErik Johnston2017-04-241-18/+11
|
* Remove unused instance variableErik Johnston2017-03-311-4/+0
|
* Doc new instance variablesErik Johnston2017-03-301-1/+8
|
* Manually calculate cache key as getcallargs is expensiveErik Johnston2017-03-301-6/+28
| | | | | This is because getcallargs recomputes the getargspec, amongst other things, which we don't need to do as its already been done
* Don't convert to deferreds when not necessaryErik Johnston2017-03-301-1/+4
|
* Fix the logcontext handling in the cache wrappers (#2077)Richard van der Hoff2017-03-301-16/+14
| | | | | | | The cache wrappers had a habit of leaking the logcontext into the reactor while the lookup function was running, and then not restoring it correctly when the lookup function had completed. It's all the fault of `preserve_context_over_{fn,deferred}` which are basically a bit broken.
* Fix caching of remote servers' signature keysRichard van der Hoff2017-03-221-63/+72
| | | | | | | | | The `@cached` decorator on `KeyStore._get_server_verify_key` was missing its `num_args` parameter, which meant that it was returning the wrong key for any server which had more than one recorded key. By way of a fix, change the default for `num_args` to be *all* arguments. To implement that, factor out a common base class for `CacheDescriptor` and `CacheListDescriptor`.
* Fix assertion to stop transaction queue getting wedgedRichard van der Hoff2017-03-151-1/+1
| | | | | | | | ... and update some docstrings to correctly reflect the types being used. get_new_device_msgs_for_remote can return a long under some circumstances, which was being stored in last_device_list_stream_id_by_dest, and was then upsetting things on the next loop.
* Add setdefault key to ExpiringCacheErik Johnston2017-03-101-0/+7
|
* CommentErik Johnston2017-02-021-1/+4
|
* CommentErik Johnston2017-02-021-0/+2
|
* Update LruCache size estimate on clearErik Johnston2017-01-181-0/+2
|
* Measure metrics of string_cacheErik Johnston2017-01-171-3/+8
|
* Fix typo in return typeErik Johnston2017-01-171-3/+2
|
* Rename and comment tree_to_leaves_iteratorErik Johnston2017-01-172-5/+8
|
* Remove needless call to evict()Erik Johnston2017-01-171-1/+0
|
* Speed up cache size calculationErik Johnston2017-01-175-46/+128
| | | | | | | | | | | Instead of calculating the size of the cache repeatedly, which can take a long time now that it can use a callback, instead cache the size and update that on insertion and deletion. This requires changing the cache descriptors to have two caches, one for pending deferreds and the other for the actual values. There's no reason to evict from the pending deferreds as they won't take up any more memory.
* Use OrderedDict in ExpiringCacheErik Johnston2017-01-161-10/+4
|
* Add support for 'iterable' to ExpiringCacheErik Johnston2017-01-161-9/+17
|
* Optionally measure size of cache by sum of length of valuesErik Johnston2017-01-132-19/+38
|
* Change get_pos_of_last_change to return upper boundErik Johnston2016-09-151-3/+4
|
* Use stream_change cache to make get_forward_extremeties_for_room cache more ↵Erik Johnston2016-09-151-0/+5
| | | | effective
* Ensure invalidation list does not grow unboundedlyErik Johnston2016-08-192-20/+16
|
* Rename to on_invalidateErik Johnston2016-08-191-16/+10
|
* Make cache_context an explicit optionErik Johnston2016-08-191-8/+27
|
* Remove lru optionErik Johnston2016-08-191-23/+8
|
* Add concept of cache contextsErik Johnston2016-08-193-20/+99
|
* Cache federation state responsesErik Johnston2016-07-211-2/+11
|
* Merge branch 'erikj/cache_perf' of github.com:matrix-org/synapse into developErik Johnston2016-06-031-10/+25
|\
| * Pull out update_results_dictErik Johnston2016-06-031-8/+7
| |
| * Small optimisation to CacheListDescriptorErik Johnston2016-06-031-2/+2
| |
| * Make cachedList go a bit fasterErik Johnston2016-06-031-10/+34
| |
* | Change CacheMetrics to be quickerErik Johnston2016-06-035-25/+44
|/ | | | | | We change it so that each cache has an individual CacheMetric, instead of having one global CacheMetric. This means that when a cache tries to increment a counter it does not need to go through so many indirections.
* Deduplicate joinsErik Johnston2016-04-071-1/+1
|
* Make the cache objects be per instance rather than being globalMark Haines2016-04-061-21/+24
|
* Fix typoMark Haines2016-03-241-1/+1
|
* Deduplicate identical /sync requestsMark Haines2016-03-241-0/+46
|
* Simplify intern_dictErik Johnston2016-03-231-17/+10
|
* Intern all the thingsErik Johnston2016-03-231-1/+57
|
* String internErik Johnston2016-03-231-0/+8
|
* Make LruCache use a dedicated _Node classErik Johnston2016-03-221-32/+41
|
* Return list, not generator.Erik Johnston2016-03-141-3/+1
|
* Use syntax that works on both py2.7 and py3Mark Haines2016-03-071-1/+1
|
* Limit stream change cache size tooErik Johnston2016-03-011-1/+5
|
* Move cache size fiddling to descriptors only. Fix testsErik Johnston2016-03-011-2/+2
|
* Add enviroment variable SYNAPSE_CACHE_FACTOR, default it to 0.1Erik Johnston2016-03-011-0/+6
|
* Reraise exceptionErik Johnston2016-03-011-0/+1
|
* Correct cache miss detectionErik Johnston2016-03-011-1/+1
|