Python 快速网络服务器
用 python 建立一个简单的网络服务器:
try:
server = HTTPServer(('', 80), MyHandler)
print 'started httpserver...'
server.serve_forever()
except KeyboardInterrupt:
print '^C received, shutting down server'
server.socket.close()
有什么方法可以让它更快吗?我相信以上是阻塞所以关心 反应慢...
谢谢!
Have a simple webserver in python:
try:
server = HTTPServer(('', 80), MyHandler)
print 'started httpserver...'
server.serve_forever()
except KeyboardInterrupt:
print '^C received, shutting down server'
server.socket.close()
Is there any way I can make it faster? I believe the above is blocking so concerned about
slow responses...
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了使 Web 服务器可扩展,请使用非阻塞 IO 套接字。一个好的 Python 框架/服务器是 Spawning:
http://pypi.python.org/pypi/Spawning/
请注意,这使得您的服务只能水平扩展(您可以轻松添加更多并发请求)。处理单个请求的延迟取决于您的代码(如何建立数据库连接等)和硬件(不使用共享托管)。您没有在问题中详细解释您正在处理的内容,因此没有足够的数据来全面回答您的问题。
To make web server scaleble use non-blocking IO sockets. A good framework/server for Python is Spawning:
http://pypi.python.org/pypi/Spawning/
Note that this makes your service scalable only in horizontally (you can easily add more concurrent requests). The delay of processing a single request depends on your code (how you make database connections, etc.) and hardware (do not use shared hosting). You did not explain in detail in your question what you are processing, so there is not enough data to give a comprehensive answer to your question.