4

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.

Damon Swayn
  • 1,326
  • 2
  • 16
  • 36

2 Answers2

4

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.

Ned Batchelder
  • 364,293
  • 75
  • 561
  • 662
  • I figured that in a proper serious implementation you would look at a proper library like Twisted etc. I'm more interested though in the provided libraries and their performance. – Damon Swayn Jan 01 '13 at 15:05
  • 3
    do you have any facts or hands-on experience to back up that claim? – dagnelies Feb 03 '16 at 18:55
3

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.

aychedee
  • 24,871
  • 8
  • 79
  • 83