diff options
author | Erik Johnston <erik@matrix.org> | 2017-01-17 17:04:46 +0000 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2017-01-17 17:04:46 +0000 |
commit | 380dba1020294b2c43ffb433b86917d0ee6cf9c0 (patch) | |
tree | b878717e071f6c8b748a5d177154138b56db649c /synapse | |
parent | Fix typo in return type (diff) | |
download | synapse-380dba1020294b2c43ffb433b86917d0ee6cf9c0.tar.xz |
Measure metrics of string_cache
Diffstat (limited to 'synapse')
-rw-r--r-- | synapse/util/caches/__init__.py | 11 |
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): |