summary refs log tree commit diff
path: root/synapse/util
diff options
context:
space:
mode:
authorRichard van der Hoff <1389908+richvdh@users.noreply.github.com>2018-04-12 12:59:36 +0100
committerGitHub <noreply@github.com>2018-04-12 12:59:36 +0100
commitd5c74b9f6c68cc49eb689c76d38c0903d48219e2 (patch)
tree1f1abc9fd8982b24c056ac92d68617297e3b263b /synapse/util
parentMerge pull request #3090 from matrix-org/erikj/processed_event_lag (diff)
parentAdd metrics for ResponseCache (diff)
downloadsynapse-d5c74b9f6c68cc49eb689c76d38c0903d48219e2.tar.xz
Merge pull request #3092 from matrix-org/rav/response_cache_metrics
Add metrics for ResponseCache
Diffstat (limited to 'synapse/util')
-rw-r--r--synapse/util/caches/response_cache.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/synapse/util/caches/response_cache.py b/synapse/util/caches/response_cache.py
index 4ecd91deb5..066fa423fd 100644
--- a/synapse/util/caches/response_cache.py
+++ b/synapse/util/caches/response_cache.py
@@ -14,6 +14,7 @@
 # limitations under the License.
 
 from synapse.util.async import ObservableDeferred
+from synapse.util.caches import metrics as cache_metrics
 
 
 class ResponseCache(object):
@@ -24,12 +25,21 @@ class ResponseCache(object):
     used rather than trying to compute a new response.
     """
 
-    def __init__(self, hs, timeout_ms=0):
+    def __init__(self, hs, name, timeout_ms=0):
         self.pending_result_cache = {}  # Requests that haven't finished yet.
 
         self.clock = hs.get_clock()
         self.timeout_sec = timeout_ms / 1000.
 
+        self._metrics = cache_metrics.register_cache(
+            "response_cache",
+            size_callback=lambda: self.size(),
+            cache_name=name,
+        )
+
+    def size(self):
+        return len(self.pending_result_cache)
+
     def get(self, key):
         """Look up the given key.
 
@@ -45,8 +55,10 @@ class ResponseCache(object):
         """
         result = self.pending_result_cache.get(key)
         if result is not None:
+            self._metrics.inc_hits()
             return result.observe()
         else:
+            self._metrics.inc_misses()
             return None
 
     def set(self, key, deferred):