From: "Daniel P. Berrange" Subject: [Patch] Make SEXPR HTTP service multi-threaded Date: Wed, 25 Oct 2006 18:58:17 +0100 Message-ID: <20061025175817.GB18644@redhat.com> Reply-To: "Daniel P. Berrange" Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="LQksG6bCIzRHxTLp" Return-path: Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org --LQksG6bCIzRHxTLp Content-Type: text/plain; charset=us-ascii Content-Disposition: inline The HTTP service used for SEXPR based RPC calls currently serializes all incoming client requests. Since some requests can take non-trivial time blocking out other clients in this way has bad consequences. The attached patch makes XenD spawn a new thread to handle each incoming HTTP request. This same approach is already taken in the XML-RPC service in XenD so I don't anticipate any multi-thread issues (at least none which don't already exist). Please apply to xen-unstable tree Signed-of-by: Daniel P. Berrange NB, this is same patch as previously submitted http://lists.xensource.com/archives/html/xen-devel/2006-10/msg00264.html Regards, Dan. -- |=- Red Hat, Engineering, Emerging Technologies, Boston. +1 978 392 2496 -=| |=- Perl modules: http://search.cpan.org/~danberr/ -=| |=- Projects: http://freshmeat.net/~danielpb/ -=| |=- GnuPG: 7D3B9505 F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 -=| --LQksG6bCIzRHxTLp Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="xen-sexpr-threaded.patch" diff -ru xen-3.0.3-testing-11633.orig/tools/python/xen/web/httpserver.py xen-3.0.3-testing-11633.new/tools/python/xen/web/httpserver.py --- xen-3.0.3-testing-11633.orig/tools/python/xen/web/httpserver.py 2006-09-28 18:52:38.000000000 -0400 +++ xen-3.0.3-testing-11633.new/tools/python/xen/web/httpserver.py 2006-10-05 19:48:41.000000000 -0400 @@ -264,7 +264,32 @@ s += x + "/" self.write(' %s/' % (s, x)) self.write("") - + +class HttpServerClient: + + def __init__(self, server, sock, addr): + self.server = server + self.sock = sock + self.addr = addr + + def process(self): + thread = threading.Thread(target=self.doProcess) + thread.setDaemon(True) + thread.start() + + def doProcess(self): + try: + rp = RequestProcessor(self.server, self.sock, self.addr) + rp.process() + except SystemExit: + raise + except Exception, ex: + print 'HttpServer>processRequest> exception: ', ex + try: + self.sock.close() + except: + pass + class HttpServer: backlog = 5 @@ -286,8 +311,8 @@ while not self.closed: (sock, addr) = self.accept() - self.processRequest(sock, addr) - + cl = HttpServerClient(self, sock, addr) + cl.process() def stop(self): self.close() @@ -314,19 +339,6 @@ except: pass - def processRequest(self, sock, addr): - try: - rp = RequestProcessor(self, sock, addr) - rp.process() - except SystemExit: - raise - except Exception, ex: - print 'HttpServer>processRequest> exception: ', ex - try: - sock.close() - except: - pass - def getServerAddr(self): return (socket.gethostname(), self.port) --LQksG6bCIzRHxTLp Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --LQksG6bCIzRHxTLp--