From: "Daniel P. Berrange" <berrange@redhat.com>
To: xen-devel@lists.xensource.com
Subject: [PATCH] Make XenD SEXPR HTTP/Unix server threaded
Date: Fri, 6 Oct 2006 01:01:15 +0100 [thread overview]
Message-ID: <20061006000115.GA3544@redhat.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 1934 bytes --]
I've spent the best part of the afternoon trying to figure out why the
virt-manager application was completely locking up while creating new
domains. The actual domain creation was being done in a background thread
to avoid blocking the main UI refresh thread, but even so it still locks
up. After a little while I discovered that both threads were blocked waiting
for data to come back from XenD, one in the wait_for_devices call, the
other in a simple /xend/node GET.
After much code inspection I eventually discovered that the HttpServer class
in xen.web.httpserver serializes all pocessing of incoming HTTP requests.
Since wait_for_devices was busy waiting for a domain to come up, the
other /xend/node GET was being blocked & hence blocking the whole client
application. Clearly this is a sub-optimal scenario because wait_for_devices
can take a *very* long time indeed (30 seconds in my case due to network
device setup failing).
I did a very trivial hack to HttpServer class to make it spawn a new thread
for every incoming request which ensures all client requests are fully
parallelized. Before building this into the Fedora RPMs, I'm just wondering
whether there was any special reason why for HttpServer being single threaded
in the first place ? I thought perhaps some synchronization / race
conditions perhaps, but given that the alternate XML-RPC server is fully
multi-threaded I figure this is unlikely.
I'm attaching the patch I knocked up - if anyone knows of a reason why this
would cause problems, please shout :-)
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
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 -=|
[-- Attachment #2: xen-sexpr-threaded.patch --]
[-- Type: text/plain, Size: 1977 bytes --]
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(' <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)
[-- Attachment #3: Type: text/plain, Size: 138 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel
reply other threads:[~2006-10-06 0:01 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20061006000115.GA3544@redhat.com \
--to=berrange@redhat.com \
--cc=xen-devel@lists.xensource.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.