Browse Source

add simple testing scripts

master
Brett Langdon 13 years ago
parent
commit
ad18261d9e
2 changed files with 58 additions and 0 deletions
  1. +55
    -0
      benchmark/benchmark.py
  2. +3
    -0
      benchmark/proxy.py

+ 55
- 0
benchmark/benchmark.py View File

@ -0,0 +1,55 @@
from multiprocessing import Process
import random
import time
import memcache
def get_next(num):
numbers = range(num)
while True:
yield random.choice(numbers)
def test(calls=1000, keys=100):
print "Starting Test"
mc = memcache.Client(["127.0.0.1:7000"])
# hack to make sure we force the connection before the first call
for server in mc.servers:
server.connect()
elapsed = 0
total = 0
numbers = get_next(keys)
hits = 0
miss = 0
for _ in range(calls):
num = numbers.next()
key = "test:%s" % num
start = time.time()
result = mc.get(key)
end = time.time()
if not result:
miss += 1
else:
hits += 1
elapsed += end - start
total += 1
print "Total: %s" % total
print "Total Elapsed: %s" % elapsed
print "Average: %s" % (elapsed / total)
print "Req/sec: %s" % (total / elapsed)
print "Hits: %s" % hits
print "Miss: %s" % miss
print "Hit Ratio: %s" % (float(hits) / float(hits + miss))
procs = []
for _ in range(10):
p = Process(target=test, args=(100000, 5000))
p.start()
procs.append(p)
for p in procs:
p.join()

+ 3
- 0
benchmark/proxy.py View File

@ -0,0 +1,3 @@
def application(environ, start_response):
start_response("200 Ok", [])
return["{}"]

Loading…
Cancel
Save