views:

78

answers:

2

I have a variable in init of a module which get loaded from the database and takes about 15 seconds.

For django development server everything is working fine but looks like with apache2 and mod_wsgi the module is loaded with every request (taking 15 seconds).

Any idea about this behavior?

Update: I have enabled daemon mode in mod wsgi, looks like its not reloading the modules now! needs more testing and I will update.

+1  A: 

I guess, you had a value of 1 for MaxClients / MaxRequestsPerChild and/or ThreadsPerChild in your Apache settings. So Apache had to startup Django for every mod_python call. That's why it took so long. If you have a wsgi-daemon, then a restart takes only place if you "touch" the wsgi script.

mawimawi
+3  A: 

You were likely ignoring the fact that in embedded mode of mod_wsgi or with mod_python, the application is multiprocess. Thus requests may go to different processes and you will see a delay the first time a process which hasn't been hit before is encountered. In mod_wsgi daemon mode the default has only a single process. That or as someone else mentioned you had MaxRequestsPerChild set to 1, which is a really bad idea.

Graham Dumpleton
I got your point, but what's with MaxRequestsPerChild set to 1 in daemon mode?
Vishal
MaxRequestsPerChild isn't related to daemon mode, it affects the Apache server child processes. Recyling Apache server child processes after a single request is very ineffecient and will affect server performance. More so if you are running Python code in embedded mode using mod_python or mod_wsgi embedded mode. Performance will likely be worse than CGI because of how Apache server child process cleanup and recycling occurs.
Graham Dumpleton
Thanks for explanation...
Vishal