I have many sites each using the same 5 Django applications (with local settings), hosted on Apache. At present each site app has its own config as follows:
WSGIDaemonProcess api_example threads=15 maximum-requests=2000
WSGIProcessGroup api_example
WSGIScriptAlias /api /var/www/sites/example/api/site.wsgi
Is it possible to share daemons between vhosts, but keep the local settings active? My aim is to save memory, and reduce the number of Apache processes launched to service requests (several of these apps are management/support consoles that are only used occasionally).
-- edit --
As Graham Dumpleton sets out here: mod_wsgi daemon mode - WSGIDaemonProcess per virtual host configuration?, it should be possible to "reach across to daemon process definition in prior virtual host so long [as it has the] same server name." Note that, as Graham points out, the WSGIApplicationGroup directive will have to be adjusted from the default, probably to %{GLOBAL} or %{ENV:variable}.
I'm not sure how to "use" server-level declarations within a vhost. Is it possible to use a server-level daemon with local settings?
The answer to the above questions, summarised as:
The answer to all of the above is Yes.
Here is an example configuration, using Debian's apache2 config as an example:
Define some wsgi daemons, eg:
In your vhost config, define a block along the following lines:
What this does:
<this_vhost>
's support app is accessed, it will attach to the wsgi_support daemon process as this is defined by the WSGIProcessGroup directive<this_vhosts>
's copy of the app is running in its own namespace (which is vital if you are running Django apps for instance, because settings are only evaluated on startup) the vhost is given its own WSGIApplicationGroup. This causes the master daemon to spawn a sub-interpreter for<this_vhost>
's app.Please read the excellent docs at http://code.google.com/p/modwsgi/wiki/ConfigurationDirectives.
Two things tripped me up initially: not defining the wsgi_daemons in the right place (which was pretty stupid) and not realising that WSGIProcessGroup directives point to WSGIDaemonProcess definitions.