Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running Django with FastCGI or with mod_python

Tags:

which would you recommend? which is faster, reliable? apache mod_python or nginx/lighttpd FastCGI?

like image 837
daniels Avatar asked Oct 28 '08 23:10

daniels


People also ask

What is FastCGI Django?

Essentially, FastCGI is an efficient way of letting an external application serve pages to a Web server. The Web server delegates the incoming Web requests (via a socket) to FastCGI, which executes the code and passes the response back to the Web server, which, in turn, passes it back to the client's Web browser.

Can I run Django on shared hosting?

This is one of the options that you can avail to deploy your Django project. The advantage of shared hosting is that it is cheap. The disadvantage is that you might not be able to deploy some advanced projects because you can not install a software on your shared host.


2 Answers

I've done both, and Apache/mod_python tended to be easier to work with and more stable. But these days I've jumped over to Apache/mod_wsgi, which is everything I've ever wanted and more:

  • Easy management of daemon processes.
  • As a result, much better process isolation (running multiple sites in the same Apache config with mod_python almost always ends in trouble -- environment variables and C extensions leak across sites when you do that).
  • Easy code reloads (set it up right and you can just touch the .wsgi file to reload instead of restarting Apache).
  • More predictable resource usage. With mod_python, a given Apache child process' memory use can jump around a lot. With mod_wsgi it's pretty stable: once everything's loaded, you know that's how much memory it'll use.
like image 195
James Bennett Avatar answered Oct 02 '22 23:10

James Bennett


lighttpd with FastCGI will be nominally faster, but really the time it takes to run your python code and any database hits it does is going to absolutely dwarf any performance benefit you get between web servers.

mod_python and apache will give you a bit more flexibility feature-wise if you want to write code outside of django that does stuff like digest auth, or any fancy HTTP header getting/setting. Perhaps you want to use other builtin features of apache such as mod_rewrite.

If memory is a concern, staying away form apache/mod_python will help a lot. Apache tends to use a lot of RAM, and the mod_python code that glues into all of the apache functionality occupies a lot of memory-space as well. Not to mention the multiprocess nature of apache tends to eat up more RAM, as each process grows to the size of it's most intensive request.

like image 25
bmdhacks Avatar answered Oct 03 '22 01:10

bmdhacks