Skip to content

Commit

Permalink
Add a separate sample rate for relatively spammy cache stats.
Browse files Browse the repository at this point in the history
  • Loading branch information
Logan Hanks committed Nov 22, 2011
1 parent c1347f6 commit bc6ecb5
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion r2/r2/lib/stats.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import random
import time

from r2.lib import cache
from r2.lib import utils

class Stats:
# Sample rate for recording cache hits/misses, relative to the global
# sample_rate.
CACHE_SAMPLE_RATE = 0.01

def __init__(self, addr, sample_rate):
if addr:
import statsd
Expand Down Expand Up @@ -38,7 +43,7 @@ def get_counter(self, name):

def cache_count(self, name, delta=1):
counter = self.get_counter('cache')
if counter:
if counter and random.random() < self.CACHE_SAMPLE_RATE:
counter.increment(name, delta=delta)

def amqp_processor(self, processor):
Expand Down

0 comments on commit bc6ecb5

Please sign in to comment.