HTTPServer, performance

Dethe Elza delza at antarcti.ca
Tue Jan 2 17:53:48 EST 2001


Sounds like garbage collection behavior, at least in Java-land.

There are lots of lightweight web servers out there, in Java and in Python.
Might want
to check out the code in one (or more) of those...

--Dethe

"Bill Scherer" <Bill.Scherer at VerizonWireless.com> wrote in message
news:mailman.977951836.8921.python-list at python.org...
> 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