Browse Source

update benchmark script, better stats output

master
Brett Langdon 13 years ago
parent
commit
8b35ce23e8
1 changed files with 36 additions and 13 deletions
  1. +36
    -13
      benchmark/benchmark.py

+ 36
- 13
benchmark/benchmark.py View File

@ -1,4 +1,4 @@
from multiprocessing import Process
from multiprocessing import Process, Queue
import random import random
import time import time
@ -11,8 +11,7 @@ def get_next(num):
yield random.choice(numbers) yield random.choice(numbers)
def test(calls=1000, keys=100):
print "Starting Test"
def test(results, calls=1000, keys=100):
mc = pymemcache.client.Client(("127.0.0.1", 7000)) mc = pymemcache.client.Client(("127.0.0.1", 7000))
elapsed = 0 elapsed = 0
@ -22,7 +21,7 @@ def test(calls=1000, keys=100):
miss = 0 miss = 0
for _ in range(calls): for _ in range(calls):
num = numbers.next() num = numbers.next()
key = "?%s" % num
key = "%s" % num
start = time.time() start = time.time()
result = mc.get(key) result = mc.get(key)
end = time.time() end = time.time()
@ -33,20 +32,44 @@ def test(calls=1000, keys=100):
elapsed += end - start elapsed += end - start
total += 1 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))
results.put((total, hits, miss))
requests_per_process = 100000
possible_urls = 5000
workers = 10
procs = [] procs = []
for _ in range(10):
p = Process(target=test, args=(100000, 5000))
results = Queue()
start = time.time()
print "Starting %s Workers" % workers
for _ in range(workers):
p = Process(target=test, args=(results, requests_per_process, possible_urls))
p.start() p.start()
procs.append(p) procs.append(p)
for p in procs: for p in procs:
p.join() p.join()
end = time.time()
elapsed = end - start
total = 0
hits = 0
miss = 0
while not results.empty():
one_total, one_hits, one_miss = results.get()
total += one_total
hits += one_hits
miss += one_miss
print "=" * 30
print "Num Workers:\t\t%s" % workers
print "Expected Requests:\t%s" % (requests_per_process * workers)
print "Actual Request:\t\t%s" % total
print "Elapsed Time (sec):\t%2.4f" % elapsed
print "Total Reqs/Sec:\t\t%.4f" % (total / elapsed)
print "Req/Sec Per Worker:\t%.4f" % ((total / elapsed) / workers)
print "Hits:\t\t\t%s" % hits
print "Misses:\t\t\t%s" % miss
print "Hit Ratio:\t\t%2.4f" % (float(hits) / float(total))
print "=" * 30

Loading…
Cancel
Save