direct-io.hg

changeset 12776:c287052a0a65

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).

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
author Ewan Mellor <ewan@xensource.com>
date Thu Dec 07 12:07:53 2006 +0000 (2006-12-07)
parents 60bbcf799384
children 531c67ed64f4
files tools/python/xen/web/httpserver.py
line diff
     1.1 --- a/tools/python/xen/web/httpserver.py	Thu Dec 07 11:52:26 2006 +0000
     1.2 +++ b/tools/python/xen/web/httpserver.py	Thu Dec 07 12:07:53 2006 +0000
     1.3 @@ -264,7 +264,32 @@ class HttpServerRequest(http.HttpRequest
     1.4              s += x + "/"
     1.5              self.write(' <a href="%s">%s</a>/' % (s, x))
     1.6          self.write("</h1>")
     1.7 -        
     1.8 +
     1.9 +class HttpServerClient:
    1.10 +
    1.11 +    def __init__(self, server, sock, addr):
    1.12 +        self.server = server
    1.13 +        self.sock = sock
    1.14 +        self.addr = addr
    1.15 +
    1.16 +    def process(self):
    1.17 +        thread = threading.Thread(target=self.doProcess)
    1.18 +        thread.setDaemon(True)
    1.19 +        thread.start()
    1.20 +
    1.21 +    def doProcess(self):
    1.22 +        try:
    1.23 +            rp = RequestProcessor(self.server, self.sock, self.addr)
    1.24 +            rp.process()
    1.25 +        except SystemExit:
    1.26 +            raise
    1.27 +        except Exception, ex:
    1.28 +            print 'HttpServer>processRequest> exception: ', ex
    1.29 +            try:
    1.30 +                self.sock.close()
    1.31 +            except:
    1.32 +                pass
    1.33 +
    1.34  class HttpServer:
    1.35  
    1.36      backlog = 5
    1.37 @@ -286,8 +311,8 @@ class HttpServer:
    1.38  
    1.39          while not self.closed:
    1.40              (sock, addr) = self.accept()
    1.41 -            self.processRequest(sock, addr)
    1.42 -
    1.43 +            cl = HttpServerClient(self, sock, addr)
    1.44 +            cl.process()
    1.45  
    1.46      def stop(self):
    1.47          self.close()
    1.48 @@ -314,19 +339,6 @@ class HttpServer:
    1.49          except:
    1.50              pass
    1.51  
    1.52 -    def processRequest(self, sock, addr):
    1.53 -        try:
    1.54 -            rp = RequestProcessor(self, sock, addr)
    1.55 -            rp.process()
    1.56 -        except SystemExit:
    1.57 -            raise
    1.58 -        except Exception, ex:
    1.59 -            print 'HttpServer>processRequest> exception: ', ex
    1.60 -            try:
    1.61 -                sock.close()
    1.62 -            except:
    1.63 -                pass
    1.64 -
    1.65      def getServerAddr(self):
    1.66          return (socket.gethostname(), self.port)
    1.67