简体   繁体   中英

Performance of Python HTTPServer and TCPServer

I've spent a few days on and off trying to get some hard statistics on what kind of performance you can expect from using the HTTPServer and/or TCPServer built-in libraries in Python.

I was wondering if anyone can give me any idea's as to how either/or would handle serving HTTP requests and if they would be able to hold up in production environments or in situations with high traffic and if anyone had any tips or clues that would improve performance in these situations. (Assuming that there is no access to external libraries like Twisted etc)

Thanks.

Neither of those built-in libraries was meant for serious production use. Get real implementations, for example, from Twisted, or Tornado, or gunicorn, etc, etc, there are lots of them. There's no need to stick with the standard library modules.

The performance, and probably the robustness of the built-in libraries is poor.

Test them. Start serving a page on localhost and then use the Apache benchmarking tool.

apt-get install apache2-utils
ab -n 10000 -c 100 http://localhost/

That makes 10000 requests, with a maximum of 100 concurrent requests.

But yeah. I wouldn't use them in production. We serve Python apps via uWSGI with the requests proxied through Nginx. It's very flexible and scales. Can the built in httpserver even handle multiple requests? It's probably single threaded. You'll find out pretty quickly when you test it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM