views:

540

answers:

1

Can someone explain the difference between apache mod_wsgi in daemon mode and django fastcgi in threaded mode. They both use threads for concurrency I think. Supposing that I'm using nginx as front end to apache mod_wsgi.

UPDATE:

I'm comparing django built in fastcgi(./manage.py method=threaded maxchildren=15) and mod_wsgi in 'daemon' mode(WSGIDaemonProcess example threads=15). They both use threads and acquire GIL, am I right?

UPDATAE 2:

So if they both are similar, is there any benefits of apache mod_wsgi against fastcgi. I see such pros of fastcgi:

  • we don't need apache
  • we consume less RAM
  • i noticed that fastcgi has lesser overhead
+2  A: 

Neither have to use threads to be able to handle concurrent requests. It depends on how you configure them. You can use multiple processes where each is single threaded if you want.

For more background on mod_wsgi process/threading models see:

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

The models are similar albeit that mod_wsgi handles process management itself. What happens in FASTCGI as far as process management depends on what FASTCGI hosting mechanism you are using and you don't say what that is.

Another difference is that FASTCGI still needs a separate FASTCGI to WSGI bridge such as flup where as mod_wsgi doesn't need any sort of bridge as implements WSGI interface natively.

Finally, FASTCGI process are an exec/fork of some supervisor process or the web server, dependent on hosting mechanism. In mod_wsgi the processes are a fork only of Apache parent process. In general this doesn't matter too much but does have some implications.

There are other differences but they arise more because mod_wsgi offers a lot more functionality and configurability than a FASTCGI hosting mechanism does.

Anyway, the question is a bit vague, can you be more specific about what it is you are wanting to know or contrast between the two and why? Answer can then perhaps be targeted better.

Graham Dumpleton
I'm comparing django built in fastcgi(./manage.py method=threaded maxchildren=15) and mod_wsgi in 'daemon' mode(WSGIDaemonProcess example threads=15).
t0ster
Yes, they both rely on multithreading to handle concurrent requests. The GIL is used even if a single threaded WSGI server, you can't easily avoid it without recompiling Python source code and disabling threading support. Do that though and you can't use mod_wsgi as it doesn't support Python which has threading disabled.
Graham Dumpleton
What do you mean "the GIL is used even if a single threaded WSGI server"? Is it used when we configure mod_wsgi to fork processes instead of threads?
t0ster
Yes, because Python is still capable of running other threads. Just because you might only use a single thread doesn't mean it can avoid the GIL as that single thread could start up background threads.
Graham Dumpleton
If we'll configure mod_wsgi as: WSGIDaemonProcess example processes=5 threads=1.Will it be used 5 python sub interpreters with a GIL per interpreter?
t0ster
Yes, because they are in different processes.
Graham Dumpleton