Skip to contentSkip to conversation

Make SEXPR HTTP service multi-threaded

PATCH In review Daniel P. Berrange 2 participants 2 messages Oct 25, 2006 – Dec 7, 2006

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Make SEXPR HTTP service multi-threaded

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

NB, this is same patch as previously submitted
http://lists.xensource.com/archives/html/xen-devel/2006-10/msg00264.html

Regards,
Dan.

Signature · 4 lines
|=- 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  -=| 
tools/python/xen/web/httpserver.py +28 -16
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
@@ -264,7 +264,32 @@
             s += x + "/"
             self.write(' <a href="%s">%s</a>/' % (s, x))
         self.write("</h1>")
-        
+
+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)
 

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw
Quoted 8 lines · Daniel P. Berrange

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

Quoted 5 lines

NB, this is same patch as previously submitted
http://lists.xensource.com/archives/html/xen-devel/2006-10/msg00264.html

Applied Daniel, thanks, and sorry for the extreme delay -- I've just found this one lurking in my inbox.

Ewan.