-
-
Save poolik/3006858 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/python | |
import multiprocessing as mp | |
import riak, os, time, uuid | |
DB = "perf_test" | |
WORKERS = 20 | |
WORK_ATTEMPTS = 20 | |
total_doc_list = [] | |
def test_writes(): | |
server = riak.RiakClient("localhost", 8098) | |
bucket = server.bucket(DB) | |
doc_list = [] | |
for i in range(WORK_ATTEMPTS): | |
test_doc = {"enabled": True, | |
"co_name" : "Test Company", | |
"admin_groups" : ["group-1", "group-2"], | |
"received_access" : {"digitar.com" : {"managed_ns_group" : "it_admins", | |
"manager_ns_group" : "admins"}}, | |
"delegated_access" : ["bobbledy.com", "virtualit.com"]} | |
# Test a new write | |
_id = str(uuid.uuid4()) + str(os.getpid()) | |
key = bucket.new(_id, test_doc) | |
key.store() | |
doc_list.append(_id) | |
# Test update | |
test_doc["admin_groups"] = ["group-3"] | |
#key = bucket.get(_id) | |
key.set_data(test_doc) | |
key.store() | |
return doc_list | |
def test_reads(doc_list): | |
server = riak.RiakClient("localhost", 8098) | |
bucket = server.bucket(DB) | |
for i in range(WORK_ATTEMPTS): | |
bucket.get(doc_list[i]).get_data() | |
def update_write_time(result): | |
global total_doc_list | |
total_doc_list.append(result) | |
if __name__ == "__main__": | |
server = riak.RiakClient("localhost", 8098) | |
bucket = server.bucket(DB) | |
# Bench writes | |
write_time = time.time() | |
pool = mp.Pool(processes=WORKERS) | |
for i in range(WORKERS): | |
pool.apply_async(test_writes, callback=update_write_time) | |
pool.close() | |
pool.join() | |
print "Write Time: %fs" % (time.time() - write_time) | |
# Bench reads | |
read_time = time.time() | |
pool = mp.Pool(processes=WORKERS) | |
for i in range(WORKERS): | |
pool.apply_async(test_reads, [total_doc_list[i]]) | |
pool.close() | |
pool.join() | |
print "Read Time: %fs" % (time.time() - read_time) | |
for key in bucket.get_keys(): | |
bucket.get(key).delete() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment