summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2013-08-28 16:10:09 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2013-08-29 00:13:22 +0100
commitd5e860be4c12a9d6655665af391ffd6f9351f8eb (patch)
tree7556d284a5971422aaf476bea54a826c41bb7f33
parent06d76645900b2a7db8f88a0ad3bf4ae66cef52f1 (diff)
downloadpoky-d5e860be4c12a9d6655665af391ffd6f9351f8eb.tar.gz
bitbake: prserv/serv: Multithread the server
This makes the PR server multithreaded and able to handle multiple connections at once which means its no longer a build bottle neck when serving one connection at a time. I've experimented and database connection for each thread seems to cause the least issues, pushing the contention for sqllite to handle itself. This means moving the db/table connection code into the actual function methods. It doesn't abstract well as a function since we need the db object around for the lifetime of the function as well as the table else we lose the connection. (Bitbake rev: bf9be2029b2bded5f532bdda4c38ae3dff5d1cf6) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--bitbake/lib/prserv/serv.py24
1 files changed, 15 insertions, 9 deletions
diff --git a/bitbake/lib/prserv/serv.py b/bitbake/lib/prserv/serv.py
index d6f3f44b04..3677f77c80 100644
--- a/bitbake/lib/prserv/serv.py
+++ b/bitbake/lib/prserv/serv.py
@@ -31,19 +31,20 @@ class Handler(SimpleXMLRPCRequestHandler):
31PIDPREFIX = "/tmp/PRServer_%s_%s.pid" 31PIDPREFIX = "/tmp/PRServer_%s_%s.pid"
32singleton = None 32singleton = None
33 33
34class PRServer(SimpleXMLRPCServer): 34import SocketServer
35class SimpleThreadedXMLRPCServer(SocketServer.ThreadingMixIn, SimpleXMLRPCServer):
36 pass
37
38class PRServer(SimpleThreadedXMLRPCServer):
35 def __init__(self, dbfile, logfile, interface, daemon=True): 39 def __init__(self, dbfile, logfile, interface, daemon=True):
36 ''' constructor ''' 40 ''' constructor '''
37 SimpleXMLRPCServer.__init__(self, interface, 41 SimpleThreadedXMLRPCServer.__init__(self, interface,
38 requestHandler=SimpleXMLRPCRequestHandler,
39 logRequests=False, allow_none=True) 42 logRequests=False, allow_none=True)
40 self.dbfile=dbfile 43 self.dbfile=dbfile
41 self.daemon=daemon 44 self.daemon=daemon
42 self.logfile=logfile 45 self.logfile=logfile
43 self.working_thread=None 46 self.working_thread=None
44 self.host, self.port = self.socket.getsockname() 47 self.host, self.port = self.socket.getsockname()
45 self.db=prserv.db.PRData(dbfile)
46 self.table=self.db["PRMAIN"]
47 self.pidfile=PIDPREFIX % (self.host, self.port) 48 self.pidfile=PIDPREFIX % (self.host, self.port)
48 49
49 self.register_function(self.getPR, "getPR") 50 self.register_function(self.getPR, "getPR")
@@ -55,13 +56,17 @@ class PRServer(SimpleXMLRPCServer):
55 56
56 def export(self, version=None, pkgarch=None, checksum=None, colinfo=True): 57 def export(self, version=None, pkgarch=None, checksum=None, colinfo=True):
57 try: 58 try:
58 return self.table.export(version, pkgarch, checksum, colinfo) 59 db = prserv.db.PRData(self.dbfile)
60 table = db["PRMAIN"]
61 return table.export(version, pkgarch, checksum, colinfo)
59 except sqlite3.Error as exc: 62 except sqlite3.Error as exc:
60 logger.error(str(exc)) 63 logger.error(str(exc))
61 return None 64 return None
62 65
63 def importone(self, version, pkgarch, checksum, value): 66 def importone(self, version, pkgarch, checksum, value):
64 return self.table.importone(version, pkgarch, checksum, value) 67 db = prserv.db.PRData(self.dbfile)
68 table = db["PRMAIN"]
69 return table.importone(version, pkgarch, checksum, value)
65 70
66 def ping(self): 71 def ping(self):
67 return not self.quit 72 return not self.quit
@@ -71,7 +76,9 @@ class PRServer(SimpleXMLRPCServer):
71 76
72 def getPR(self, version, pkgarch, checksum): 77 def getPR(self, version, pkgarch, checksum):
73 try: 78 try:
74 return self.table.getValue(version, pkgarch, checksum) 79 db = prserv.db.PRData(self.dbfile)
80 table = db["PRMAIN"]
81 return table.getValue(version, pkgarch, checksum)
75 except prserv.NotFoundError: 82 except prserv.NotFoundError:
76 logger.error("can not find value for (%s, %s)",version, checksum) 83 logger.error("can not find value for (%s, %s)",version, checksum)
77 return None 84 return None
@@ -177,7 +184,6 @@ class PRServSingleton(object):
177 self.prserv = PRServer(self.dbfile, self.logfile, self.interface) 184 self.prserv = PRServer(self.dbfile, self.logfile, self.interface)
178 self.prserv.start() 185 self.prserv.start()
179 self.host, self.port = self.prserv.getinfo() 186 self.host, self.port = self.prserv.getinfo()
180 del self.prserv.db
181 187
182 def getinfo(self): 188 def getinfo(self):
183 return (self.host, self.port) 189 return (self.host, self.port)