diff options
author | Erik Johnston <erik@matrix.org> | 2021-04-26 10:37:26 +0100 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2021-04-26 10:39:54 +0100 |
commit | 567fe5e387dc29ab1de30481f1e37c5047bb25cf (patch) | |
tree | 07f17d243334205835466b1afb9d0ab15e138f98 | |
parent | Ignore singletons (diff) | |
download | synapse-567fe5e387dc29ab1de30481f1e37c5047bb25cf.tar.xz |
Make TRACK_MEMORY_USAGE configurable
-rw-r--r-- | synapse/app/generic_worker.py | 1 | ||||
-rw-r--r-- | synapse/app/homeserver.py | 1 | ||||
-rw-r--r-- | synapse/config/cache.py | 11 | ||||
-rw-r--r-- | synapse/python_dependencies.py | 2 | ||||
-rw-r--r-- | synapse/util/caches/lrucache.py | 2 |
5 files changed, 15 insertions, 2 deletions
diff --git a/synapse/app/generic_worker.py b/synapse/app/generic_worker.py index 7b2ac3ca64..d831f793b9 100644 --- a/synapse/app/generic_worker.py +++ b/synapse/app/generic_worker.py @@ -452,6 +452,7 @@ def start(config_options): config.server.update_user_directory = False synapse.events.USE_FROZEN_DICTS = config.use_frozen_dicts + synapse.util.caches.lrucache.TRACK_MEMORY_USAGE = config.caches.track_memory_usage hs = GenericWorkerServer( config.server_name, diff --git a/synapse/app/homeserver.py b/synapse/app/homeserver.py index 8be8b520eb..fd7958cecd 100644 --- a/synapse/app/homeserver.py +++ b/synapse/app/homeserver.py @@ -339,6 +339,7 @@ def setup(config_options): sys.exit(0) events.USE_FROZEN_DICTS = config.use_frozen_dicts + synapse.util.caches.lrucache.TRACK_MEMORY_USAGE = config.caches.track_memory_usage hs = SynapseHomeServer( config.server_name, diff --git a/synapse/config/cache.py b/synapse/config/cache.py index 41b9b3f51f..91165ee1ce 100644 --- a/synapse/config/cache.py +++ b/synapse/config/cache.py @@ -17,6 +17,8 @@ import re import threading from typing import Callable, Dict +from synapse.python_dependencies import DependencyException, check_requirements + from ._base import Config, ConfigError # The prefix for all cache factor-related environment variables @@ -189,6 +191,15 @@ class CacheConfig(Config): ) self.cache_factors[cache] = factor + self.track_memory_usage = cache_config.get("track_memory_usage", False) + if self.track_memory_usage: + try: + check_requirements("cache_memory") + except DependencyException as e: + raise ConfigError( + e.message # noqa: B306, DependencyException.message is a property + ) + # Resize all caches (if necessary) with the new factors we've loaded self.resize_all_caches() diff --git a/synapse/python_dependencies.py b/synapse/python_dependencies.py index 77176a6cd9..d709033c27 100644 --- a/synapse/python_dependencies.py +++ b/synapse/python_dependencies.py @@ -121,7 +121,7 @@ CONDITIONAL_REQUIREMENTS = { # hiredis is not a *strict* dependency, but it makes things much faster. # (if it is not installed, we fall back to slow code.) "redis": ["txredisapi>=1.4.7", "hiredis"], - "cache_memroy": ["pympler"], + "cache_memory": ["pympler"], } ALL_OPTIONAL_REQUIREMENTS = set() # type: Set[str] diff --git a/synapse/util/caches/lrucache.py b/synapse/util/caches/lrucache.py index b018733288..1719b0a1ca 100644 --- a/synapse/util/caches/lrucache.py +++ b/synapse/util/caches/lrucache.py @@ -60,7 +60,7 @@ except ImportError: # Whether to track estimated memory usage of the LruCaches. -TRACK_MEMORY_USAGE = True +TRACK_MEMORY_USAGE = False # Function type: the type used for invalidation callbacks |