meder omuraliev
meder omuraliev

Reputation: 186552

mod_wsgi excessively slow at startup?

I'm developing a django website which for production uses mod_wsgi - there are barely any visitors so anytime I visit it seems mod wsgi starts up and opens the python processes - it takes about 1-2 entire minutes for it to fully load.

Is there anything I could do to not make it slow on initial startup? Is this a common problem or could it just be an issue with my configuration?

Upvotes: 4

Views: 3207

Answers (2)

Kevin Parker
Kevin Parker

Reputation: 17206

Just some more light on this. You don't want to use prefork MPM period, it will cause 1x mod_wsgi process for each of the pre-forked processes.

The best way to overcome this is to run the WSGI process in Daemon mode with the worker MPM.

https://docs.djangoproject.com/en/dev/howto/deployment/wsgi/modwsgi/#using-mod-wsgi-daemon-mode

Edit:

Also note that you MUST specify the group otherwise each HTTPD process seemed to create its own mod_wsgi process after all the connections were closed.

WSGIScriptAlias / /usr/local/apache2/htdocs/ABC.com/build/wsgi.py WSGIPassAuthorization On WSGILazyInitialization Off WSGIDaemonProcess ABC.com user=apache group=apache display-name=%{GROUP} processes=1 threads=256 WSGIProcessGroup ABC.com

Upvotes: 0

Graham Dumpleton
Graham Dumpleton

Reputation: 58523

It shouldn't take that long even if you used a suboptimal configuration of using embedded mode and Apache prefork MPM. Although, you could make things worse if you had MaxRequestsPerChild set to 1 for Apache processes.

Suggestions are, make sure you are using mod_wsgi daemon mode and run with a single multithreaded process (the default settings for WSGIDaemonProcess). This will ensure at least that there is only one instance of Django and not potentially one per Apache server process.

As confirmation of what you are doing, edit your question and post snippet of your current Apache configuration showing how to set up mod_wsgi bits. Include also whether you are using Apache prefork or worker MPM, determinable by running 'httpd -V' and what platform you are using.

BTW, have you tried a simple hello world WSGI program to validate your installation? See 'http://code.google.com/p/modwsgi/wiki/QuickConfigurationGuide'. And have you tried with an empty Django site, rather than your real one to see whether it is your changes?

Upvotes: 6

Related Questions