summary refs log tree commit diff
path: root/synapse/config/cache.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2021-05-05 16:54:36 +0100
committerGitHub <noreply@github.com>2021-05-05 16:54:36 +0100
commitef889c98a6cde0cfa95f7fdaf7f99ec3c1e9bb7f (patch)
tree2809f8a1254ec06f888753aa487b140317dd880d /synapse/config/cache.py
parentLimit how often GC happens by time. (#9902) (diff)
downloadsynapse-ef889c98a6cde0cfa95f7fdaf7f99ec3c1e9bb7f.tar.xz
Optionally track memory usage of each LruCache (#9881)
This will double count slightly in the presence of interned strings. It's off by default as it can consume a lot of resources.

Diffstat (limited to 'synapse/config/cache.py')
-rw-r--r--synapse/config/cache.py11
1 files changed, 11 insertions, 0 deletions
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()