This repository was archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Time external cache response time #9904
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
af71cd1
Time external cache response time
erikjohnston 13adfc4
Newsfile
erikjohnston 6d2ae1f
Update synapse/replication/tcp/external_cache.py
erikjohnston 514c58e
Update description
erikjohnston 15bf312
Update synapse/replication/tcp/external_cache.py
erikjohnston File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Time response time for external cache requests. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ | |
import logging | ||
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.util import json_decoder, json_encoder | ||
|
@@ -35,6 +35,20 @@ | |
labelnames=["cache_name", "hit"], | ||
) | ||
|
||
response_timer = Histogram( | ||
"synapse_external_cache_response_time_seconds", | ||
"Time taken to get a response from Redis for a request", | ||
labelnames=["method"], | ||
buckets=( | ||
0.001, | ||
0.002, | ||
0.005, | ||
0.01, | ||
0.02, | ||
0.05, | ||
), | ||
) | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
@@ -72,23 +86,25 @@ async def set(self, cache_name: str, key: str, value: Any, expiry_ms: int) -> No | |
|
||
logger.debug("Caching %s %s: %r", cache_name, key, encoded_value) | ||
|
||
return await make_deferred_yieldable( | ||
self._redis_connection.set( | ||
self._get_redis_key(cache_name, key), | ||
encoded_value, | ||
pexpire=expiry_ms, | ||
with response_timer.labels("set").time(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it make sense to add the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think so, the times shouldn't depend on what we're caching (and I'm a bit cautious about the fact it adds a bunch of extra metrics). Broadly these should be super quick, and if they're not then something is wrong/congested. |
||
return await make_deferred_yieldable( | ||
self._redis_connection.set( | ||
self._get_redis_key(cache_name, key), | ||
encoded_value, | ||
pexpire=expiry_ms, | ||
) | ||
) | ||
) | ||
|
||
async def get(self, cache_name: str, key: str) -> Optional[Any]: | ||
"""Look up a key/value in the named cache.""" | ||
|
||
if self._redis_connection is None: | ||
return None | ||
|
||
result = await make_deferred_yieldable( | ||
self._redis_connection.get(self._get_redis_key(cache_name, key)) | ||
) | ||
with response_timer.labels("get").time(): | ||
result = await make_deferred_yieldable( | ||
self._redis_connection.get(self._get_redis_key(cache_name, key)) | ||
) | ||
|
||
logger.debug("Got cache result %s %s: %r", cache_name, key, result) | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.