views:

121

answers:

1

Firstly:

  1. I understand what WSGI is and how to use it
  2. I understand what "other" methods (Apache mod-python, fcgi, et al) are, and how to use them
  3. I understand their practical differences

What I don't understand is how each of the various "other" methods work compared to something like UWSGI, behind the scenes. Does your server (Nginx, etc) route the request to your WSGI application and UWSGI creates a new Python interpreter for each request routed to it? How much different is is from the other more traditional / monkey patched methods is WSGI (aside from the different, easier Python interface that WSGI offers)? What light bulb moment am I missing?

+4  A: 

Except for CGI, a new Python interpreter is nearly never created per request. Read:

http://blog.dscpl.com.au/2009/03/python-interpreter-is-not-created-for.html

This was written in respect of mod_python but also applies to mod_wsgi and any WSGI hosting mechanism that uses persistent processes.

Also read:

http://www.python.org/dev/peps/pep-0333/#environ-variables

There you will find described the 'wsgi.run_once' variable described. This is used to indicate to a WSGI application when a hosting mechanism is used which would see a process only handling one request and then being exited, ie., CGI. Thus, write a test hello world application which dumps out the WSGI environment and see what it is set to for what you are using.

Also pay attention to the 'wsgi.multiprocess' and 'wsgi.multithread' variables. They tell you if a multi process server is being used such that there are multiple instances of your application handling requests at the same time. The 'wsgi.multithread' variable tells you if the process itself is handling multiple requests in concurrent threads in same process.

For more on multiprocess and multithread models in relation to Apache embedded systems, such as mod_python and mod_wsgi, and mod_wsgi daemon mode, see:

http://code.google.com/p/modwsgi/wiki/ProcessesAndThreading

Graham Dumpleton
@Graham thanks for your answer.
orokusaki