mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-04-27 03:00:12 -04:00
Collect stats on stalecache hits and misses.
This commit is contained in:
@@ -61,7 +61,12 @@ from r2.lib.lock import make_lock_factory
|
||||
from r2.lib.manager import db_manager
|
||||
from r2.lib.plugin import PluginLoader
|
||||
from r2.lib.providers import select_provider
|
||||
from r2.lib.stats import Stats, CacheStats, StatsCollectingConnectionPool
|
||||
from r2.lib.stats import (
|
||||
CacheStats,
|
||||
StaleCacheStats,
|
||||
Stats,
|
||||
StatsCollectingConnectionPool,
|
||||
)
|
||||
from r2.lib.translation import get_active_langs, I18N_PATH
|
||||
from r2.lib.utils import config_gold_price, thread_dump
|
||||
|
||||
@@ -774,7 +779,10 @@ class Globals(object):
|
||||
def reset_caches():
|
||||
for name, chain in cache_chains.iteritems():
|
||||
chain.reset()
|
||||
chain.stats = CacheStats(self.stats, name)
|
||||
if isinstance(chain, StaleCacheChain):
|
||||
chain.stats = StaleCacheStats(self.stats, name)
|
||||
else:
|
||||
chain.stats = CacheStats(self.stats, name)
|
||||
self.cache_chains = cache_chains
|
||||
|
||||
self.reset_caches = reset_caches
|
||||
|
||||
@@ -694,10 +694,13 @@ class StaleCacheChain(CacheChain):
|
||||
if stale_value is not None:
|
||||
if self.stats:
|
||||
self.stats.cache_hit()
|
||||
self.stats.stale_hit()
|
||||
return stale_value # never return stale data into the
|
||||
# LocalCache, or people that didn't
|
||||
# say they'll take stale data may
|
||||
# get it
|
||||
else:
|
||||
self.stats.stale_miss()
|
||||
|
||||
value = self.realcache.get(key)
|
||||
if value is None:
|
||||
@@ -735,6 +738,12 @@ class StaleCacheChain(CacheChain):
|
||||
ret[k] = v
|
||||
keys.remove(k)
|
||||
|
||||
stale_hits = len(stale_values)
|
||||
stale_misses = len(keys)
|
||||
if self.stats:
|
||||
self.stats.stale_hit(stale_hits)
|
||||
self.stats.stale_miss(stale_misses)
|
||||
|
||||
if keys:
|
||||
values = self.realcache.simple_get_multi(keys)
|
||||
if values and stale:
|
||||
|
||||
@@ -449,6 +449,30 @@ class CacheStats:
|
||||
self.parent.cache_count_multi(data, sample_rate=sample_rate)
|
||||
|
||||
|
||||
class StaleCacheStats(CacheStats):
|
||||
def __init__(self, parent, cache_name):
|
||||
CacheStats.__init__(self, parent, cache_name)
|
||||
self.stale_hit_name = '%s.stale.hit' % self.cache_name
|
||||
self.stale_miss_name = '%s.stale.miss' % self.cache_name
|
||||
self.stale_total_name = '%s.stale.total' % self.cache_name
|
||||
|
||||
def stale_hit(self, delta=1):
|
||||
if delta:
|
||||
data = {
|
||||
self.stale_hit_name: delta,
|
||||
self.stale_total_name: delta,
|
||||
}
|
||||
self.parent.cache_count_multi(data)
|
||||
|
||||
def stale_miss(self, delta=1):
|
||||
if delta:
|
||||
data = {
|
||||
self.stale_miss_name: delta,
|
||||
self.stale_total_name: delta,
|
||||
}
|
||||
self.parent.cache_count_multi(data)
|
||||
|
||||
|
||||
class StatsCollectingConnectionPool(pool.ConnectionPool):
|
||||
def __init__(self, keyspace, stats=None, *args, **kwargs):
|
||||
pool.ConnectionPool.__init__(self, keyspace, *args, **kwargs)
|
||||
|
||||
Reference in New Issue
Block a user