开发者

When deploying python, what web server options do we have? is the process inefficient at all?

开发者 https://www.devze.com 2022-12-28 22:19 出处:网络
I think in the past python scripts would run off CGI, which would create a new thread for each process.

I think in the past python scripts would run off CGI, which would create a new thread for each process.

I am a newbie so I'm not really sure, what options do we have?

Is 开发者_C百科the web server pipeline that python works under any more/less effecient than say php?


You can still use CGI if you want, but the normal approach these days is using WSGI on the Python side, e.g. through mod_wsgi on Apache or via bridges to FastCGI on other web servers. At least with mod_wsgi, I know of no inefficiencies with this approach.

BTW, your description of CGI ("create a new thread for each process") is inaccurate: what it does is create a new process for each query's service (and that process typically needs to open a database connection, import all needed modules, etc etc, which is what may make it slow even on platforms where forking a process, per se, is pretty fast, such as all Unix variants).


I would suggest Django http://www.djangoproject.com. It is very convenient to use, has everything you need for making web services. The most efficient way to use it is to run it as via Apache's mod_wsgi, and make Apache itself serve the static files.

This generally has better performance than solutions such as CGI and mod-python, as the Python process running the web service runs separate from the main web server, so it can cache stuff and easily re-use resources (like DB handles).

Also, you can then tweak the number of worker threads for Apache and your web application separately, resulting in better scalability.


I suggest cherrypy (http://www.cherrypy.org/). It is very convenient to use, has everything you need for making web services, but still quite simple (no mega-framework). The most efficient way to use it is to run it as self-contained server on localhost and put it behind Apache via a Proxy statement, and make apache itself serve the static files.

This generally has better performance than solutions such as CGI and mod-python, as the Python process running the web service runs separate from the main web server, so it can cache stuff and easily re-use resources (like DB handles).

Also, you can then tweak the number of worker threads for Apache and your web application separately, resulting in better scalability.

0

精彩评论

暂无评论...
验证码 换一张
取 消