diff --git a/benchmark/benchmark.py b/benchmark/benchmark.py index 771c9cc..e9af54f 100644 --- a/benchmark/benchmark.py +++ b/benchmark/benchmark.py @@ -1,4 +1,4 @@ -from multiprocessing import Process +from multiprocessing import Process, Queue import random import time @@ -11,8 +11,7 @@ def get_next(num): 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)) elapsed = 0 @@ -22,7 +21,7 @@ def test(calls=1000, keys=100): miss = 0 for _ in range(calls): num = numbers.next() - key = "?%s" % num + key = "%s" % num start = time.time() result = mc.get(key) end = time.time() @@ -33,20 +32,44 @@ def test(calls=1000, keys=100): 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)) + results.put((total, hits, miss)) +requests_per_process = 100000 +possible_urls = 5000 +workers = 10 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() procs.append(p) for p in procs: 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