forked from MirrorHub/synapse
Track cache invalidations (#12000)
Currently we only track evictions due to size or time constraints.
This commit is contained in:
parent
dc9fe61050
commit
0dbbe33a65
4 changed files with 10 additions and 1 deletions
1
changelog.d/12000.feature
Normal file
1
changelog.d/12000.feature
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Track cache invalidations in Prometheus metrics, as already happens for cache eviction based on size or time.
|
|
@ -56,6 +56,7 @@ response_cache_total = Gauge("synapse_util_caches_response_cache:total", "", ["n
|
||||||
class EvictionReason(Enum):
|
class EvictionReason(Enum):
|
||||||
size = auto()
|
size = auto()
|
||||||
time = auto()
|
time = auto()
|
||||||
|
invalidation = auto()
|
||||||
|
|
||||||
|
|
||||||
@attr.s(slots=True, auto_attribs=True)
|
@attr.s(slots=True, auto_attribs=True)
|
||||||
|
|
|
@ -133,6 +133,11 @@ class ExpiringCache(Generic[KT, VT]):
|
||||||
raise KeyError(key)
|
raise KeyError(key)
|
||||||
return default
|
return default
|
||||||
|
|
||||||
|
if self.iterable:
|
||||||
|
self.metrics.inc_evictions(EvictionReason.invalidation, len(value.value))
|
||||||
|
else:
|
||||||
|
self.metrics.inc_evictions(EvictionReason.invalidation)
|
||||||
|
|
||||||
return value.value
|
return value.value
|
||||||
|
|
||||||
def __contains__(self, key: KT) -> bool:
|
def __contains__(self, key: KT) -> bool:
|
||||||
|
|
|
@ -560,8 +560,10 @@ class LruCache(Generic[KT, VT]):
|
||||||
def cache_pop(key: KT, default: Optional[T] = None) -> Union[None, T, VT]:
|
def cache_pop(key: KT, default: Optional[T] = None) -> Union[None, T, VT]:
|
||||||
node = cache.get(key, None)
|
node = cache.get(key, None)
|
||||||
if node:
|
if node:
|
||||||
delete_node(node)
|
evicted_len = delete_node(node)
|
||||||
cache.pop(node.key, None)
|
cache.pop(node.key, None)
|
||||||
|
if metrics:
|
||||||
|
metrics.inc_evictions(EvictionReason.invalidation, evicted_len)
|
||||||
return node.value
|
return node.value
|
||||||
else:
|
else:
|
||||||
return default
|
return default
|
||||||
|
|
Loading…
Reference in a new issue