HTTPServer, performance

Bill Scherer Bill.Scherer at VerizonWireless.com
Wed Dec 27 15:58:32 EST 2000


Hello eveyone, hope you had a nice holiday...

Question: Is the code below the proper way to create a multi-threaded
http server in Python, and what kind of performance should one expect
out of it?

The code below works.  It's an extremely stripped down verison of my
current project which really runs under J(p)ython. I was unsatisfied
with performance, so I stripped out all that wasn't web server and tried
it under CPython and JPython.  

With the code below, CPython does about 12 tps on a dual 733 Mhz machine
under RedHat 6.2. JPython is only slightly slower (when using a JVM that
uses native threads and therefore both processors).  Apache on the same
box does over 70 tps with a greater number of simulated users (100 vs
25).

One thing I do see with both CPython and JPython running this code is
random stalling.  ie. The server will be happily serving requests, then
for no apparent reason, it justs stops.  CPU load drops during the
stall, although it never gets very high. Two, maybe three, seconds
later, it resumes serving.  Pings during this time show no change to
network latency (0.4ms).

Any and all help is appreciated.

Thanks!

--------------------------------------------------------------------------------

import SocketServer, BaseHTTPServer

PORT = 9777

class HTTPServer(SocketServer.ThreadingMixIn,
BaseHTTPServer.HTTPServer):
    pass

class RequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
    def do_GET(self):
        self.send_response(200)
        self.send_header("Content-type", 'text/plain')
        self.end_headers()
        self.wfile.write('hello world')
        return

if __name__ == '__main__':
    httpd = HTTPServer(('', PORT), RequestHandler)
    print 'serving on port', PORT
    httpd.serve_forever()


-- 
William K. Scherer
Sr. Member of Applications Staff - Verizon Wireless
Bill.Scherer_at_VerizonWireless.com




More information about the Python-list mailing list