mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2024-10-01 11:49:51 -04:00
Time external cache response time (#9904)
This commit is contained in:
parent
b85821aca2
commit
e3bc4617fc
1
changelog.d/9904.misc
Normal file
1
changelog.d/9904.misc
Normal file
@ -0,0 +1 @@
|
|||||||
|
Time response time for external cache requests.
|
@ -15,7 +15,7 @@
|
|||||||
import logging
|
import logging
|
||||||
from typing import TYPE_CHECKING, Any, Optional
|
from typing import TYPE_CHECKING, Any, Optional
|
||||||
|
|
||||||
from prometheus_client import Counter
|
from prometheus_client import Counter, Histogram
|
||||||
|
|
||||||
from synapse.logging.context import make_deferred_yieldable
|
from synapse.logging.context import make_deferred_yieldable
|
||||||
from synapse.util import json_decoder, json_encoder
|
from synapse.util import json_decoder, json_encoder
|
||||||
@ -35,6 +35,20 @@ get_counter = Counter(
|
|||||||
labelnames=["cache_name", "hit"],
|
labelnames=["cache_name", "hit"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
response_timer = Histogram(
|
||||||
|
"synapse_external_cache_response_time_seconds",
|
||||||
|
"Time taken to get a response from Redis for a cache get/set request",
|
||||||
|
labelnames=["method"],
|
||||||
|
buckets=(
|
||||||
|
0.001,
|
||||||
|
0.002,
|
||||||
|
0.005,
|
||||||
|
0.01,
|
||||||
|
0.02,
|
||||||
|
0.05,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -72,6 +86,7 @@ class ExternalCache:
|
|||||||
|
|
||||||
logger.debug("Caching %s %s: %r", cache_name, key, encoded_value)
|
logger.debug("Caching %s %s: %r", cache_name, key, encoded_value)
|
||||||
|
|
||||||
|
with response_timer.labels("set").time():
|
||||||
return await make_deferred_yieldable(
|
return await make_deferred_yieldable(
|
||||||
self._redis_connection.set(
|
self._redis_connection.set(
|
||||||
self._get_redis_key(cache_name, key),
|
self._get_redis_key(cache_name, key),
|
||||||
@ -86,6 +101,7 @@ class ExternalCache:
|
|||||||
if self._redis_connection is None:
|
if self._redis_connection is None:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
with response_timer.labels("get").time():
|
||||||
result = await make_deferred_yieldable(
|
result = await make_deferred_yieldable(
|
||||||
self._redis_connection.get(self._get_redis_key(cache_name, key))
|
self._redis_connection.get(self._get_redis_key(cache_name, key))
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user