Created
September 9, 2015 16:10
-
-
Save nomadhacker/ef34b308f650573a794d to your computer and use it in GitHub Desktop.
Benchmark Memcached
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import memcache | |
import argparse | |
import time | |
parser = argparse.ArgumentParser(description='Benchmark Memcached Implementation') | |
parser.add_argument('-s', | |
'--server', | |
help='Memcached Server') | |
parser.add_argument('-p', | |
'--port', | |
help='Memcached Port') | |
parser.add_argument('-x', | |
'--x', | |
help='Number of iterations') | |
args = parser.parse_args() | |
server = args.server | |
port = args.port | |
x_iter = int(args.x) | |
conn_addr = '%s:11211' % server | |
mc = memcache.Client([conn_addr], debug=0) | |
write_start = time.time() | |
for i in range(x_iter): | |
key = 'key_%s' % i | |
mc.set(key, 1) | |
write_end = time.time() | |
read_start = time.time() | |
for i in range(x_iter): | |
for i in range(10): | |
key = 'key_%s' % i | |
v = mc.get(key) | |
if not v: | |
print 'failed to get' | |
read_end = time.time() | |
total_write = write_end - write_start | |
avg_write = total_write / x_iter | |
total_read = read_end - read_start | |
avg_read = total_read / (x_iter * 10) | |
print 'Total Time for write: %sms' % total_write | |
print 'Avg write time per op: %sms' % avg_write | |
print '\n' | |
print 'Total Time for read: %sms' % total_read | |
print 'Avg read time per op: %sms' % avg_read |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment