mirror of
https://github.com/matrix-org/synapse.git
synced 2025-02-06 23:35:47 +00:00
Add metrics tracking for eviction to ResponseCache (#16028)
Track whether the ResponseCache is evicting due to invalidation or due to time.
This commit is contained in:
parent
a4102d2a5f
commit
7cbb2a00d1
1
changelog.d/16028.misc
Normal file
1
changelog.d/16028.misc
Normal file
@ -0,0 +1 @@
|
|||||||
|
Collect additional metrics from `ResponseCache` for eviction.
|
@ -36,7 +36,7 @@ from synapse.logging.opentracing import (
|
|||||||
)
|
)
|
||||||
from synapse.util import Clock
|
from synapse.util import Clock
|
||||||
from synapse.util.async_helpers import AbstractObservableDeferred, ObservableDeferred
|
from synapse.util.async_helpers import AbstractObservableDeferred, ObservableDeferred
|
||||||
from synapse.util.caches import register_cache
|
from synapse.util.caches import EvictionReason, register_cache
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -167,7 +167,7 @@ class ResponseCache(Generic[KV]):
|
|||||||
# the should_cache bit, we leave it in the cache for now and schedule
|
# the should_cache bit, we leave it in the cache for now and schedule
|
||||||
# its removal later.
|
# its removal later.
|
||||||
if self.timeout_sec and context.should_cache:
|
if self.timeout_sec and context.should_cache:
|
||||||
self.clock.call_later(self.timeout_sec, self.unset, key)
|
self.clock.call_later(self.timeout_sec, self._entry_timeout, key)
|
||||||
else:
|
else:
|
||||||
# otherwise, remove the result immediately.
|
# otherwise, remove the result immediately.
|
||||||
self.unset(key)
|
self.unset(key)
|
||||||
@ -185,6 +185,12 @@ class ResponseCache(Generic[KV]):
|
|||||||
Args:
|
Args:
|
||||||
key: key used to remove the cached value
|
key: key used to remove the cached value
|
||||||
"""
|
"""
|
||||||
|
self._metrics.inc_evictions(EvictionReason.invalidation)
|
||||||
|
self._result_cache.pop(key, None)
|
||||||
|
|
||||||
|
def _entry_timeout(self, key: KV) -> None:
|
||||||
|
"""For the call_later to remove from the cache"""
|
||||||
|
self._metrics.inc_evictions(EvictionReason.time)
|
||||||
self._result_cache.pop(key, None)
|
self._result_cache.pop(key, None)
|
||||||
|
|
||||||
async def wrap(
|
async def wrap(
|
||||||
|
Loading…
Reference in New Issue
Block a user