Last active
March 2, 2016 16:14
-
-
Save dhaikney/bb5171ca3de21ed6e95b to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env - python | |
from couchbase.bucket import Bucket | |
import threading | |
import sys | |
from multiprocessing.dummy import Pool as ThreadPool | |
TIMEOUT=10 | |
if len(sys.argv) != 7: | |
print "Usage: " + sys.argv[0] + " <host> <bucket> <count> <size> <conns> <threads>" | |
sys.exit() | |
this_host = sys.argv[1] | |
this_bucket = sys.argv[2] | |
this_count = int(sys.argv[3]) | |
this_size = int(sys.argv[4]) | |
conns = int(sys.argv[5]) | |
num_threads = int(sys.argv[6]) | |
prefix = "DH_" | |
conns_per_thread = conns / num_threads | |
def make_some_conns_and_do_some_ops(tid): | |
print "starting tid: " , tid | |
cb_connections=[None] * conns | |
for x in range(0, conns_per_thread): | |
cb_connections[x] = Bucket("couchbase://"+this_host+"/"+this_bucket,password="hello", timeout=TIMEOUT) | |
for x in range (this_count): | |
for i in range(0, conns_per_thread): | |
try: | |
key = "{0}{1}-{2}".format(prefix,x,i) | |
cb_connections[i].get(key) | |
except Exception: | |
pass | |
# | |
# for tid in range (1,4): | |
# t = threading.Thread(target=make_some_conns_and_do_some_ops,args=(tid)) | |
# t.daemon = True | |
# t.start() | |
pool = ThreadPool(num_threads) | |
results = pool.map(make_some_conns_and_do_some_ops, range(0,num_threads)) | |
print "waiting" | |
#close the pool and wait for the work to finish | |
pool.close() | |
pool.join() | |
print "bye" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment