2

I was reading through here: https://code.google.com/p/modwsgi/wiki/ReloadingSourceCode

We have a python app hosted over a wide array of load-balanced servers, and sometimes it takes a long time for a request to come into a server that has a low priority in the load balancer. Meaning we may a really long wait time (while that server's wsgi daemon spins up) quite a long time after a deploy.

I have a fix for this when we actually deploy, but we also have automatic apache (graceful) restarts on the server array. Is restarting apache the same thing as touching my wsgi file ? Does wsgi wait until a request comes into that particular daemon to compile and spin up or does it autoload on apache restart ?

cbron
  • 123
  • 3
  • I just did a couple of tests on an Apache 2.4. My tests were inconclusive. First I used a `reload`, which left the previous wsgi daemon in place, and after the next request the previous wsgi daemon was gone, and a new was there. But after a restart I tried a `reload` again, and this time the new wsgi daemon started without first seeing a request. As far as I remember, when I was running Apache 2.2, the wsgi daemon never started until the first request came in. – kasperd Aug 14 '14 at 23:19

1 Answers1

4

Use preloading to force load the application when the process starts up rather than relying on the default of lazy loading on first request for the application.

If using a sufficiently new enough version of mod_wsgi, instead of using:

WSGIDaemonProcess xxx
WSGIProcessGroup xxx
WSGIApplicationGroup %{GLOBAL}

WSGIScriptAlias / /some/path/wsgi.py

Use:

WSGIDaemonProcess xxx

WSGIScriptAlias / /some/path/wsgi.py process-group=xxx application-group=%{GLOBAL}

By supplying both process-group and application-group arguments to WSGIScriptAlias, mod_wsgi will know for certain what daemon process group and sub interpreter context the application will in the end run and so it can preload it on startup.

If you are on a very out of date distro with an older version of mod_wsgi, there is an alternate way of doing a similar thing using the WSGIImportScript directive.

Graham Dumpleton
  • 6,090
  • 2
  • 21
  • 19