Technological Wanderings - wgsi http://www.technologicalwanderings.co.uk/taxonomy/term/117 en mod_wsgi http://www.technologicalwanderings.co.uk/node/62 <div class="field field-name-taxonomy-vocabulary-1 field-type-taxonomy-term-reference field-label-above"><div class="field-label">Keywords:&nbsp;</div><div class="field-items"><div class="field-item even"><a href="/taxonomy/term/117">wgsi</a></div><div class="field-item odd"><a href="/taxonomy/term/118">python</a></div><div class="field-item even"><a href="/taxonomy/term/119">mod_wsgi</a></div></div></div><div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even"><p>mod_wsgi in daemon mode is a massive improvement over both mod_python and mod_wsgi in embedded mode.</p> <p>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.</p> <p>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.</p> <p>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.</p> <p>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.</p> <p>Here's my configuration:<br /><code><br /> WSGIDaemonProcess unique_process_id processes=2 threads=4 maximum-requests=100 display-name=%{GROUP}<br /> WSGIScriptAlias / /var/www/website/wsgi.py<br /> WSGIProcessGroup unique_process_id<br /></code><br /> 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.</p> <p>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.</p> </div></div></div> Sat, 09 May 2009 11:41:22 +0000 techuser 62 at http://www.technologicalwanderings.co.uk http://www.technologicalwanderings.co.uk/node/62#comments