collectd-memcached-bucket

Grab stats for individual buckets in the NorthMemCouchScaleBase bucket engine and shove them into collectd
git clone https://code.literati.org/collectd-memcached-bucket.git
Log | Files | Refs

genload.py (940B)


      1 #!/usr/bin/python
      2 import random, time
      3 import mc_bin_client
      4 
      5 def mkkey():
      6     return hex(random.randint(0, 0xffff))
      7 
      8 def mkval():
      9     return str(random.randint(0, 10000))
     10 
     11 def main():
     12     mc = mc_bin_client.MemcachedClient()
     13     mc.sasl_auth_cram_md5('admin', 'nai0eeNi')
     14 
     15     start = time.time()
     16     ops = 0
     17     while True:
     18         key = mkkey()
     19         val = mkval()
     20         op = random.randint(0, 3)
     21         try:
     22             if op == 0:
     23                 mc.set(key, 60, 0, val)
     24             elif op == 1:
     25                 mc.get(key)
     26             elif op == 2:
     27                 mc.incr(key, exp=60)
     28             elif op == 3:
     29                 mc.decr(key, exp=60)
     30         except mc_bin_client.MemcachedError as e:
     31             if e.status != 1:
     32                 print e.message
     33             
     34         ops += 1
     35 
     36         if ops % 10000 == 0:
     37             print 'ops/sec = {0}'.format(ops/(time.time() - start))
     38 
     39 
     40 if __name__ == '__main__':
     41     main()
     42