Python 快速网络服务器 [英] Python Fast Webserver

查看:53
本文介绍了Python 快速网络服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在python中有一个简单的网络服务器:

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...

谢谢!

推荐答案

为了使 Web 服务器可扩展,请使用非阻塞 IO 套接字.一个好的 Python 框架/服务器是 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.

这篇关于Python 快速网络服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆