You are here

mod_wsgi

mod_wsgi

mod_wsgi in daemon mode is a massive improvement over both mod_python and mod_wsgi in embedded mode.

mod_python was causing Apache2 to use the full memory and swap of my 256MB Slicehost server; that's around 700MB total commit. The same happened with mod_wsgi initially. The reason being that for each Apache process launched, the whole of my application's footprint was fetched into memory.

Partial solutions are to reduce the number of Apache processes, which bring its own problems when you don't have enough to serve your users.

mod_wsgi in daemon mode solves this by launching separate python-specific processes to look after your code, leaving Apache to look after incoming requests and static files. A single python process can look after a hundred Apaches.

It should have only taken a few minutes to configure daemon mode over embedded, but it was not obvious to me how to start the daemon. I spent a lot of time researching how to do it until I finally read the correct part of the documentation: mod_wsgi actually looks after this for you; there's no separate daemon to start.

Here's my configuration:

WSGIDaemonProcess unique_process_id processes=2 threads=4 maximum-requests=100 display-name=%{GROUP}
WSGIScriptAlias / /var/www/website/wsgi.py
WSGIProcessGroup unique_process_id

That's all you need over the daemon mode. There are a huge number of configuration options to tweak the way it runs which I won't go into here, but you can make it do pretty much whatever you need.

In terms of performance, I suspect that a daemon won't be as fast as a python-per-request, but since embedded in my experience eventually leads to swapping, daemon modes wins out overall.

Subscribe to RSS - mod_wsgi