summary refs log tree commit diff
path: root/synapse
diff options
context:
space:
mode:
authorErik Johnston <erikj@jki.re>2017-01-18 10:57:39 +0000
committerGitHub <noreply@github.com>2017-01-18 10:57:39 +0000
commitf648313f9827b977d7dc0899da136b36e21e7958 (patch)
tree31ea0e87a1fd3a3ce51b773fe57c7f82cc7df939 /synapse
parentMerge pull request #1818 from matrix-org/erikj/state_auth_splitout_split (diff)
parentMeasure metrics of string_cache (diff)
downloadsynapse-f648313f9827b977d7dc0899da136b36e21e7958.tar.xz
Merge pull request #1821 from matrix-org/erikj/cache_metrics_string_intern
Measure metrics of string_cache
Diffstat (limited to 'synapse')
-rw-r--r--synapse/util/caches/__init__.py11
1 files changed, 8 insertions, 3 deletions
diff --git a/synapse/util/caches/__init__.py b/synapse/util/caches/__init__.py
index ebd715c5dc..8a7774a88e 100644
--- a/synapse/util/caches/__init__.py
+++ b/synapse/util/caches/__init__.py
@@ -40,8 +40,8 @@ def register_cache(name, cache):
     )
 
 
-_string_cache = LruCache(int(5000 * CACHE_SIZE_FACTOR))
-caches_by_name["string_cache"] = _string_cache
+_string_cache = LruCache(int(100000 * CACHE_SIZE_FACTOR))
+_stirng_cache_metrics = register_cache("string_cache", _string_cache)
 
 
 KNOWN_KEYS = {
@@ -69,7 +69,12 @@ KNOWN_KEYS = {
 def intern_string(string):
     """Takes a (potentially) unicode string and interns using custom cache
     """
-    return _string_cache.setdefault(string, string)
+    new_str = _string_cache.setdefault(string, string)
+    if new_str is string:
+        _stirng_cache_metrics.inc_hits()
+    else:
+        _stirng_cache_metrics.inc_misses()
+    return new_str
 
 
 def intern_dict(dictionary):