diff options
author | Erik Johnston <erik@matrix.org> | 2016-06-02 11:29:44 +0100 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2016-06-02 11:37:50 +0100 |
commit | 266eb3bf26916ba2eacc0ecebdc586de0c98c5f3 (patch) | |
tree | 4bda3cf485d15785601c22756af199ed4a23bbce /synapse/util/caches/descriptors.py | |
parent | Merge branch 'develop' of github.com:matrix-org/synapse into erikj/timings (diff) | |
download | synapse-266eb3bf26916ba2eacc0ecebdc586de0c98c5f3.tar.xz |
Change CacheMetrics to be quicker
We change it so that each cache has an individual CacheMetric, instead of having one global CacheMetric. This means that when a cache tries to increment a counter it does not need to go through so many indirections.
Diffstat (limited to 'synapse/util/caches/descriptors.py')
-rw-r--r-- | synapse/util/caches/descriptors.py | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/synapse/util/caches/descriptors.py b/synapse/util/caches/descriptors.py index ccf6c0b3c6..f48ff29c6a 100644 --- a/synapse/util/caches/descriptors.py +++ b/synapse/util/caches/descriptors.py @@ -22,7 +22,7 @@ from synapse.util.logcontext import ( PreserveLoggingContext, preserve_context_over_deferred, preserve_context_over_fn ) -from . import caches_by_name, DEBUG_CACHES, cache_counter +from . import DEBUG_CACHES, register_cache from twisted.internet import defer @@ -51,6 +51,7 @@ class Cache(object): "keylen", "sequence", "thread", + "metrics", ) def __init__(self, name, max_entries=1000, keylen=1, lru=True, tree=False): @@ -68,7 +69,7 @@ class Cache(object): self.keylen = keylen self.sequence = 0 self.thread = None - caches_by_name[name] = self.cache + self.metrics = register_cache(name, self.cache) def check_thread(self): expected_thread = self.thread @@ -83,10 +84,10 @@ class Cache(object): def get(self, key, default=_CacheSentinel): val = self.cache.get(key, _CacheSentinel) if val is not _CacheSentinel: - cache_counter.inc_hits(self.name) + self.metrics.inc_hits() return val - cache_counter.inc_misses(self.name) + self.metrics.inc_misses() if default is _CacheSentinel: raise KeyError() |