diff options
author | Erik Johnston <erik@matrix.org> | 2022-02-15 14:31:04 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-15 14:31:04 +0000 |
commit | 0dbbe33a65c17cdb1ad41d6109b5629029dce886 (patch) | |
tree | 1813f0acb252c5c2a383db79e1842e3d4a738178 | |
parent | Fix incorrect `get_rooms_for_user` for remote user (#11999) (diff) | |
download | synapse-0dbbe33a65c17cdb1ad41d6109b5629029dce886.tar.xz |
Track cache invalidations (#12000)
Currently we only track evictions due to size or time constraints.
Diffstat (limited to '')
-rw-r--r-- | changelog.d/12000.feature | 1 | ||||
-rw-r--r-- | synapse/util/caches/__init__.py | 1 | ||||
-rw-r--r-- | synapse/util/caches/expiringcache.py | 5 | ||||
-rw-r--r-- | synapse/util/caches/lrucache.py | 4 |
4 files changed, 10 insertions, 1 deletions
diff --git a/changelog.d/12000.feature b/changelog.d/12000.feature new file mode 100644 index 0000000000..246cc87f0b --- /dev/null +++ b/changelog.d/12000.feature @@ -0,0 +1 @@ +Track cache invalidations in Prometheus metrics, as already happens for cache eviction based on size or time. diff --git a/synapse/util/caches/__init__.py b/synapse/util/caches/__init__.py index 15debd6c46..1cbc180eda 100644 --- a/synapse/util/caches/__init__.py +++ b/synapse/util/caches/__init__.py @@ -56,6 +56,7 @@ response_cache_total = Gauge("synapse_util_caches_response_cache:total", "", ["n class EvictionReason(Enum): size = auto() time = auto() + invalidation = auto() @attr.s(slots=True, auto_attribs=True) diff --git a/synapse/util/caches/expiringcache.py b/synapse/util/caches/expiringcache.py index 67ee4c693b..c6a5d0dfc0 100644 --- a/synapse/util/caches/expiringcache.py +++ b/synapse/util/caches/expiringcache.py @@ -133,6 +133,11 @@ class ExpiringCache(Generic[KT, VT]): raise KeyError(key) return default + if self.iterable: + self.metrics.inc_evictions(EvictionReason.invalidation, len(value.value)) + else: + self.metrics.inc_evictions(EvictionReason.invalidation) + return value.value def __contains__(self, key: KT) -> bool: diff --git a/synapse/util/caches/lrucache.py b/synapse/util/caches/lrucache.py index 7548b38548..45ff0de638 100644 --- a/synapse/util/caches/lrucache.py +++ b/synapse/util/caches/lrucache.py @@ -560,8 +560,10 @@ class LruCache(Generic[KT, VT]): def cache_pop(key: KT, default: Optional[T] = None) -> Union[None, T, VT]: node = cache.get(key, None) if node: - delete_node(node) + evicted_len = delete_node(node) cache.pop(node.key, None) + if metrics: + metrics.inc_evictions(EvictionReason.invalidation, evicted_len) return node.value else: return default |