python - Parallel calls to CouchDB -
i'd stress test clouddb cluster python3 can't multithreading work properly. have used google , there many ways this, of them way complicated me and/or use case.
what try save document couchdb on 3 nodes @ same time. how use simple way of multithreading possible this?
import couchdb import random import time import _thread servers = { "pizerogrijs": "http://admin:admin@pizerogrijs.local:5984/", "pizerogeel": "http://admin:admin@pizerogeel.local:5984/", "pizeroroze": "http://admin:admin@pizeroroze.local:5984/" } databasename = 'testhijs' class bank(object): def __init__(self): self.dbs = {} s in servers: self.dbs[s] = couchdb.server(servers[s])[databasename] def showdbs(self): print(self.dbs) def randomwrite(self, data): randomdb = self.dbs[random.choice(list(self.dbs))] return(randomdb.save(data)) def directwrite(self, server, data): start = time.time() directdb = self.dbs[server] end = time.time() print(directdb.save(data)) print(end - start) def streskip(server): db.directwrite(server, {"test": "thijs"}) db = bank() _thread.start_new_thread(streskip('pizerogrijs'), ()) _thread.start_new_thread(streskip('pizerogeel'), ()) _thread.start_new_thread(streskip('pizeroroze'), ()) while 1: pass
the response is:
/usr/bin/python3.6 /home/thijs/repos/databos/test.py ('f4e66074fdae56c6de6b1d744033eb63', '1-a8238505469902134486a6744284a43a') 9.5367431640625e-07 traceback (most recent call last): file "/home/thijs/repos/databos/test.py", line 39, in <module> _thread.start_new_thread(streskip('pizerogrijs'), ()) typeerror: first arg must callable process finished exit code 1
i needed add arguments in tuple , not directly. so.
_thread.start_new_thread(streskip, ('pizerogrijs',)) _thread.start_new_thread(streskip, ('pizerogeel',)) _thread.start_new_thread(streskip, ('pizeroroze',))
the rest of code fine , simple way of multi threading find.
Comments
Post a Comment