mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-08-08 15:02:24 -04:00
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.
This commit is contained in:
parent
065e739d6e
commit
73c7112433
8 changed files with 82 additions and 70 deletions
|
@ -61,9 +61,6 @@ class CounterMetricTestCase(unittest.TestCase):
|
|||
'vector{method="PUT"} 1',
|
||||
])
|
||||
|
||||
# Check that passing too few values errors
|
||||
self.assertRaises(ValueError, counter.inc)
|
||||
|
||||
|
||||
class CallbackMetricTestCase(unittest.TestCase):
|
||||
|
||||
|
@ -138,27 +135,27 @@ class CacheMetricTestCase(unittest.TestCase):
|
|||
def test_cache(self):
|
||||
d = dict()
|
||||
|
||||
metric = CacheMetric("cache", lambda: len(d))
|
||||
metric = CacheMetric("cache", lambda: len(d), "cache_name")
|
||||
|
||||
self.assertEquals(metric.render(), [
|
||||
'cache:hits 0',
|
||||
'cache:total 0',
|
||||
'cache:size 0',
|
||||
'cache:hits{name="cache_name"} 0',
|
||||
'cache:total{name="cache_name"} 0',
|
||||
'cache:size{name="cache_name"} 0',
|
||||
])
|
||||
|
||||
metric.inc_misses()
|
||||
d["key"] = "value"
|
||||
|
||||
self.assertEquals(metric.render(), [
|
||||
'cache:hits 0',
|
||||
'cache:total 1',
|
||||
'cache:size 1',
|
||||
'cache:hits{name="cache_name"} 0',
|
||||
'cache:total{name="cache_name"} 1',
|
||||
'cache:size{name="cache_name"} 1',
|
||||
])
|
||||
|
||||
metric.inc_hits()
|
||||
|
||||
self.assertEquals(metric.render(), [
|
||||
'cache:hits 1',
|
||||
'cache:total 2',
|
||||
'cache:size 1',
|
||||
'cache:hits{name="cache_name"} 1',
|
||||
'cache:total{name="cache_name"} 2',
|
||||
'cache:size{name="cache_name"} 1',
|
||||
])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue