-
-
Save poolik/3006852 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 couchdb, os, time, uuid | |
URL = "http://localhost:5984" | |
DB = "perf_test" | |
WORKERS = 20 | |
WORK_ATTEMPTS = 20 | |
total_doc_list = [] | |
def test_writes(): | |
db = couchdb.Database(URL + "/" + DB) | |
doc_list = [] | |
for i in range(WORK_ATTEMPTS): | |
_id = str(uuid.uuid4()) + "-" + str(os.getpid()) | |
test_doc = {"_id" : _id, | |
"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, _rev = db.save(test_doc) | |
doc_list.append(_id) | |
# Test update | |
test_doc["_id"] = _id | |
test_doc["_rev"] = _rev | |
test_doc["admin_groups"] = ["group-3"] | |
db.save(test_doc) | |
return doc_list | |
def test_reads(doc_list): | |
db = couchdb.Database(URL + "/" + DB) | |
for i in range(WORK_ATTEMPTS): | |
db[doc_list[i]] | |
def update_write_time(result): | |
global total_doc_list | |
total_doc_list.append(result) | |
if __name__ == "__main__": | |
server = couchdb.Server(URL) | |
server.create(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) | |
server.delete(DB) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment