WSGIDaemonProcess <user> processes=5 threads=1 python-home=/path/to
WSGIProcessGroup <user>
WSGIRestrictEmbedded On
WSGILazyInitialization On
WSGIApplicationGroup %{GLOBAL}
My application uses Gdal which is not thread safe. The documentation suggests using wsgi with threads=1
. If the apache configuration is using a threaded mpm-worker
will threads=1
guarantee thread safety?
Apache settings:
KeepAlive Off
SetEnvIf X-Forwarded-SSL on HTTPS=1
ServerLimit 1
StartServers 1
MaxRequestWorkers 5
MinSpareThreads 1
MaxSpareThreads 3
ThreadsPerChild 5
A complementary quote to the accepted answer is the following:
StartServers 2
ThreadsPerChild 25
WSGIDaemonProcess processes=1 threads=15
In the case of the WSGI application, the Apache child worker processes only act as a proxy, forwarding the requests across to the mod_wsgi daemon mode process(es) for handling.
Thus, with 2 Apache child worker processes, maximum number of connections is 50 (where each has 25 threads). These Apache child worker processes accept connections for both static file requests and dynamic requests which are then proxied across to the mod_wsgi daemon mode process. With only a single mod_wsgi daemon mode process, the WSGI application itself will be able to handle 15 concurrent requests.
If there are requests being handled by mod_wsgi daemon mode process, because the Apache child worker processes is proxying the requests and responses, a thread is still consumed for the life of the request in the Apache child worker processes. The 35 (50-15) additional threads in Apache child worker processes would still be available for handling static requests, keep alive connections and acting as a buffering mechanism for pending dynamic requests against WSGI application. The latter particularly useful for slow clients as apache child worker processes will not forward request onto mod_wsgi daemon process until full request information available.
Note that just because mod_wsgi daemon mode process can only handle 15 concurrent requests doesn't mean that it can only handle that many requests per second. How many requests per second is going to be dictated by how slow your application is and what contention there is on shared resources. The latter have an impact on whether operations need to be serialised.
Overall, just think of mod_wsgi daemon mode as being similar to using mod_proxy in front of a separate back end web server. In this case though mod_wsgi has created the daemon processes and is managing them on your behalf.
Graham Dumpleton