Python Fast Webserver

冷暖自知 提交于 2019-12-12 06:24:57

问题


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!


回答1:


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.



来源:https://stackoverflow.com/questions/7257010/python-fast-webserver

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!