[Trac] mod_python vs cgi

Emmanuel Blot manu.blot at gmail.com
Thu Jun 16 19:44:50 CDT 2005


> Is there any comparison that can help us choose which to use, and what
> the benefits/costs are?

mod_python is faster than CGI.

With CGI, each request starts a new process, which means the web
server needs to spawn a new process, load and execute the Python
engine, which in turn loads the appropriate libraries, (parses the
Trac source code or) loads the precompiled Python bytecode, and
executes it. Then the Python engine can process the actual request,
send the result back to the web client, and eventually quit.

Conversely, mod_python runs the same sequence only for the first
request. The Python engine, and the Trac engine and data stays in
memory, waiting for other requests. Subsequent requests are therefore
executed faster than with CGI. Have a look at the mod_python page for
details.

However, mod_python does not fit for debugging or developing Trac code.

Security concerns: mod_python runs an extension module for Apache,
i.e. within the Apache process space, which might be a
security/stability issue. Moreover, all requests in mod_python run as
threads, i.e. all requests are handled within the same address space.

ModPython is a (very) little bit more difficult to use, as you first
need to install and enable it through your web server configuration.
ModPython is only available for Apache, I think. If you're using a IIS
server, you should go for CGI or FastCGI.

FastCGI is run in its own address space (separate process from the web
server), but can be reused for subsequent request, which makes its
execution faster than CGI.

There are some other pros and cons, but you get the big picture. You
probably want to have a look at:
http://www.modpython.org/
http://www.fastcgi.com/devkit/doc/fastcgi-whitepaper/fastcgi.htm

It's late, I hope I did not write stupid things ;-)

-- 
Manu


More information about the Trac mailing list