Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Allow configuration of Synapse's cache without using synctl or environment variables #6391

Merged
merged 66 commits into from
May 11, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
99ab65a
fix up logging to use rapidjson
hawkowl Oct 24, 2019
d684ec8
benchmarks
hawkowl Oct 24, 2019
135fdaa
update linting
hawkowl Oct 31, 2019
f36f3ab
Merge remote-tracking branch 'origin/develop' into hawkowl/structured…
hawkowl Oct 31, 2019
73cfdeb
fix
hawkowl Oct 31, 2019
babf4ea
Merge branch 'develop' into hawkowl/structured-logging-perf
hawkowl Nov 1, 2019
e55591d
Merge remote-tracking branch 'origin/develop' into hawkowl/structured…
hawkowl Nov 4, 2019
c580eb3
revert this
hawkowl Nov 4, 2019
f888515
Merge remote-tracking branch 'origin/develop' into hawkowl/structured…
hawkowl Nov 4, 2019
a14831d
Move cache configuration into a homeserver config option, instead of …
hawkowl Nov 20, 2019
50fcb4a
Re-sync every so often, in case caches appear
hawkowl Nov 21, 2019
8439ce5
Merge remote-tracking branch 'origin/develop' into hawkowl/structured…
hawkowl Nov 25, 2019
92d4d13
fixes
hawkowl Dec 2, 2019
d70be18
Merge remote-tracking branch 'origin/develop' into hawkowl/structured…
hawkowl Dec 2, 2019
c11c8ad
more fixes
hawkowl Dec 2, 2019
0e368ee
more fixes
hawkowl Dec 2, 2019
f7ec526
add some LruCache benchmarks
hawkowl Dec 2, 2019
e174b2d
fix style
hawkowl Dec 2, 2019
946650c
Merge remote-tracking branch 'origin/develop' into hawkowl/benchmark-…
hawkowl Dec 3, 2019
9735a08
newsfile
hawkowl Dec 3, 2019
c76a412
Merge remote-tracking branch 'origin/develop' into hawkowl/cache-conf…
hawkowl Jan 16, 2020
0a02b2a
cleanup
hawkowl Jan 16, 2020
a21702f
cleanup so it can refer to late-config
hawkowl Jan 16, 2020
125c5a0
Merge branch 'hawkowl/benchmark-lrucache' into hawkowl/cache-config-w…
hawkowl Jan 16, 2020
0b069b7
make expiring caches resizeable
hawkowl Jan 16, 2020
a96b5d9
Load cache factors from the environment, and add a test.
hawkowl Jan 21, 2020
2f4dbfa
document as well as refactor so that CacheMetric is not nested
hawkowl Jan 21, 2020
ac020de
fix style
hawkowl Jan 21, 2020
18c1dbf
don't need this comment
hawkowl Jan 21, 2020
4aeb6fb
Merge remote-tracking branch 'origin/develop' into hawkowl/cache-conf…
hawkowl Feb 17, 2020
5f508e7
add tests for individual cache sizing, and fix up the individual cach…
hawkowl Feb 17, 2020
2619891
fix
hawkowl Feb 17, 2020
0fc0a7d
fix
hawkowl Feb 27, 2020
965e259
fixes
hawkowl Feb 27, 2020
f004cee
Merge remote-tracking branch 'origin/develop' into hawkowl/cache-conf…
hawkowl Feb 27, 2020
546c23e
Merge branch 'develop' of github.com:matrix-org/synapse into hawkowl/…
anoadragon453 Apr 3, 2020
7117b89
Update synapse/config/cache.py
anoadragon453 Apr 3, 2020
4ed7aa1
Move separate CacheConfig global vars into a single global dict
anoadragon453 Apr 3, 2020
be0737a
Move _DEFAULT_CONFIG to class method
anoadragon453 Apr 3, 2020
14fbf27
Merge branch 'hawkowl/cache-config-without-synctl' of github.com:matr…
anoadragon453 Apr 3, 2020
cc1dd98
lint
anoadragon453 Apr 3, 2020
de25659
Fix typing
anoadragon453 Apr 3, 2020
6e979a1
sample config
anoadragon453 Apr 3, 2020
fec13be
Fix lint
anoadragon453 Apr 6, 2020
905c833
Add some mypy ignores
anoadragon453 Apr 6, 2020
f300c08
Merge branch 'develop' of github.com:matrix-org/synapse into hawkowl/…
anoadragon453 Apr 24, 2020
28f7f59
Re-add default_size_factor multipler. Revert _max_size modification
anoadragon453 Apr 24, 2020
5f3eddc
Refactor globals in CacheConfig
anoadragon453 Apr 24, 2020
fcc9c3a
dict() -> {}
anoadragon453 Apr 24, 2020
5acca12
Some variable cleanups in cache.py
anoadragon453 Apr 27, 2020
fdef3ad
Make add_resizable_cache args clearer in cache tests
anoadragon453 Apr 27, 2020
ca98241
lint
anoadragon453 Apr 27, 2020
48709a9
Pull global cache prefix from environment by default
anoadragon453 Apr 30, 2020
9e3a9ba
Make config follow the guidelines
anoadragon453 May 1, 2020
fa56e16
sample config
anoadragon453 May 1, 2020
83cf583
Allow creating an LruCache that's not affected by cache factor
anoadragon453 May 1, 2020
424215a
Fix cache: config block parsing
anoadragon453 May 1, 2020
c7f3bf6
Environment takes precedence over config values
anoadragon453 May 1, 2020
485f177
fix tests
anoadragon453 May 1, 2020
fe89050
Fix and clarify config comments
anoadragon453 May 1, 2020
ae6070b
Move event_cache_size to CacheConfig
anoadragon453 May 1, 2020
4448633
Follow config file conventions. Move cache config location
anoadragon453 May 4, 2020
f8ed432
Attempt to explain the default global cache factor
anoadragon453 May 4, 2020
c1b339b
Merge branch 'develop' of github.com:matrix-org/synapse into hawkowl/…
anoadragon453 May 4, 2020
06fbfc2
Merge branch 'develop' of github.com:matrix-org/synapse into hawkowl/…
anoadragon453 May 5, 2020
edb04df
Merge branch 'develop' of github.com:matrix-org/synapse into hawkowl/…
anoadragon453 May 11, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion synapse/storage/data_stores/main/events_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ def __init__(self, database: Database, db_conn, hs):
super(EventsWorkerStore, self).__init__(database, db_conn, hs)

self._get_event_cache = Cache(
"*getEvent*", keylen=3, max_entries=hs.config.caches.event_cache_size
"*getEvent*",
keylen=3,
max_entries=hs.config.caches.event_cache_size,
apply_cache_factor_from_config=False,
)

self._event_fetch_lock = threading.Condition()
Expand Down
11 changes: 10 additions & 1 deletion synapse/util/caches/descriptors.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,15 @@ class Cache(object):
"_pending_deferred_cache",
)

def __init__(self, name, max_entries=1000, keylen=1, tree=False, iterable=False):
def __init__(
self,
name,
max_entries=1000,
keylen=1,
tree=False,
iterable=False,
apply_cache_factor_from_config=True,
):
anoadragon453 marked this conversation as resolved.
Show resolved Hide resolved
cache_type = TreeCache if tree else dict
self._pending_deferred_cache = cache_type()

Expand All @@ -98,6 +106,7 @@ def __init__(self, name, max_entries=1000, keylen=1, tree=False, iterable=False)
cache_type=cache_type,
size_callback=(lambda d: len(d)) if iterable else None,
evicted_callback=self._on_evicted,
apply_cache_factor_from_config=apply_cache_factor_from_config,
)

self.name = name
Expand Down
2 changes: 1 addition & 1 deletion synapse/util/caches/expiringcache.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ def __init__(
an item on access. Defaults to False.
iterable (bool): If true, the size is calculated by summing the
sizes of all entries, rather than the number of entries.

"""
self._cache_name = cache_name

self._original_max_size = max_len

self._max_size = int(max_len * cache_config.properties.default_factor_size)

self._clock = clock
Expand Down
12 changes: 11 additions & 1 deletion synapse/util/caches/lrucache.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def __init__(
cache_type=dict,
size_callback=None,
evicted_callback=None,
apply_cache_factor_from_config=True,
):
"""
Args:
Expand All @@ -73,13 +74,22 @@ def __init__(
evicted_callback (func(int)|None):
if not None, called on eviction with the size of the evicted
entry

apply_cache_factor_from_config (bool): If true, `max_size` will be
multiplied by a cache factor derived from the homeserver config.
"""
cache = cache_type()
self.cache = cache # Used for introspection.

# Save the original max size, and apply the default size factor.
self._original_max_size = max_size
self.max_size = int(max_size * cache_config.properties.default_factor_size)
# We previously didn't apply the cache factor here, and as such some caches were
# not affected by the global cache factor. Add an option here to disable applying
# the cache factor when a cache is created
if apply_cache_factor_from_config:
self.max_size = int(max_size * cache_config.properties.default_factor_size)
else:
self.max_size = int(max_size)

list_root = _Node(None, None, None, None)
list_root.next_node = list_root
Expand Down