Michael P. Jung: Efficient Django hosting for the masses

Tags: django, djangocon, python

Hosting a huge number of php sites is no problem for a hoster. It is a bit more involved when django sites are involved. He’s co-founder of http://pyrox.eu that tries doing django hosting The Right Way (fully replicated python hosting).

Mass hosting means many websites from different users sharing CPU/disk/memory resources. Suitable for small and medium sites. So “mass” hosting, not “massive” hosting.

Python implications: WSGI applications are long-running processes so they consume memory 24/7, for instance. For developers, going with a mass hosting solution should mean reduced costs and less maintenance (no OS level upgrades). Being developer friendly is important. SSH access, svn/git/hg/bzr tools must be available.

A good efficient stack is apache with mod_wsgi and daemon processes. That last bit is essential. Excellent performance due to persistent apps. But restarting apache (for a config change) means re-starting all wsgi processes. It is apache after all :-)

The best stack would be a webserver separate from the wsgi container. So he searched for the perfect wsgi container. Low memory usage and simple configuration please.

He also wants threads. The normal response is “just use more processes”. But the application might require quite some memory. And firing up a couple of extra processes costs memory.

He looked at many wsgi containers, but in the end mod_wsgi was pretty good after all, provided you switched off as many apache modules as possible. Note: apache is only used as a wsgi container, there’s a separate nginx web server in front!

Eventual setup. Web server: nginx. Wsgi container: apache+mod_wsgi. And a separate apache (with NoFollowSymlinks) for the static files as nginx follows symlinks by default, which is a security risk.

Replication: database, filesytem. Of course you have to use RAID. Backups are important, but they are an entirely different story. You don’t want to wait hours before a restore succeeded: that’s why you have replication. HAProxy and nginx deal with failover well enough.

 
vanrees.org logo

Reinout van Rees

My name is Reinout van Rees and I program in Python, I live in the Netherlands, I cycle recumbent bikes and I have a model railway.

Weblog feeds

Most of my website content is in my weblog. You can keep up to date by subscribing to the automatic feeds (for instance with Google reader):