From ad18261d9e9861b1f518aafe28ecd4dff982d866 Mon Sep 17 00:00:00 2001 From: brettlangdon Date: Fri, 19 Jul 2013 23:28:02 -0400 Subject: [PATCH] add simple testing scripts --- benchmark/benchmark.py | 55 ++++++++++++++++++++++++++++++++++++++++++ benchmark/proxy.py | 3 +++ 2 files changed, 58 insertions(+) create mode 100644 benchmark/benchmark.py create mode 100644 benchmark/proxy.py diff --git a/benchmark/benchmark.py b/benchmark/benchmark.py new file mode 100644 index 0000000..66a4cbb --- /dev/null +++ b/benchmark/benchmark.py @@ -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() diff --git a/benchmark/proxy.py b/benchmark/proxy.py new file mode 100644 index 0000000..876262b --- /dev/null +++ b/benchmark/proxy.py @@ -0,0 +1,3 @@ +def application(environ, start_response): + start_response("200 Ok", []) + return["{}"]