简体   繁体   English

Python HTTPServer和TCPServer的性能

[英]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. 我花了几天时间试图获得一些关于在Python中使用HTTPServer和/或TCPServer内置库可以获得什么样的性能的硬统计数据。

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. 我想知道是否有人可以给我任何关于如何处理HTTP请求以及它们是否能够在生产环境中或在高流量情况下如果有任何提示或线索可以改善在这些情况下的表现。 (Assuming that there is no access to external libraries like Twisted etc) (假设无法访问像Twisted等外部库)

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. 获得真正的实现,例如,从Twisted,Tornado或gunicorn等等,有很多。 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. 开始在localhost上提供页面,然后使用Apache基准测试工具。

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

That makes 10000 requests, with a maximum of 100 concurrent requests. 这会产生10000个请求,最多100个并发请求。

But yeah. 但是,是的。 I wouldn't use them in production. 我不会在生产中使用它们。 We serve Python apps via uWSGI with the requests proxied through Nginx. 我们通过uWSGI为通过Nginx代理的请求提供Python应用程序。 It's very flexible and scales. 它非常灵活,可以扩展。 Can the built in httpserver even handle multiple requests? 内置的httpserver甚至可以处理多个请求吗? It's probably single threaded. 它可能是单线程的。 You'll find out pretty quickly when you test it. 测试时你会发现很快。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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