mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-02 10:56:06 -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
|
@ -13,7 +13,7 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from synapse.util.caches import cache_counter, caches_by_name
|
||||
from synapse.util.caches import register_cache
|
||||
|
||||
import logging
|
||||
|
||||
|
@ -49,7 +49,7 @@ class ExpiringCache(object):
|
|||
|
||||
self._cache = {}
|
||||
|
||||
caches_by_name[cache_name] = self._cache
|
||||
self.metrics = register_cache(cache_name, self._cache)
|
||||
|
||||
def start(self):
|
||||
if not self._expiry_ms:
|
||||
|
@ -78,9 +78,9 @@ class ExpiringCache(object):
|
|||
def __getitem__(self, key):
|
||||
try:
|
||||
entry = self._cache[key]
|
||||
cache_counter.inc_hits(self._cache_name)
|
||||
self.metrics.inc_hits()
|
||||
except KeyError:
|
||||
cache_counter.inc_misses(self._cache_name)
|
||||
self.metrics.inc_misses()
|
||||
raise
|
||||
|
||||
if self._reset_expiry_on_get:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue