Inspired by Justin Lilly, I spent some time looking at various ways of running python web applications with an eye to performance. Nicholas Piël has done some great work testing and documenting many of them. Gevent looks like a great option as does CherryPy, but uWSGI caught my eye because it provides an nginx module and I’m already running lots of nginx. Since its fairly new, my stock nginx from the Ubuntu Karmic repository doesn’t come with uWSGI, but compiling it in is trivial.

So I’ve added uwsgi and nginx + uwsgi to my launchpad ppa for anyone out there who’d like to give it a spin on Karmic. My initial impressions are very positive. If you want to try it out, you can add my ppa to your apt sources and simply run:

sudo apt-get install nginx uwsgi

Starting up the wsgi server is easy. You can pass it a wsgi script to run, or you can pass it later dynamically using an environment variable ‘UWSGI_SCRIPT’. Here’s how I’m starting it right now:

sudo -u www-data uwsgi -s :9001 -d /var/log/uwsgi.log

This simply starts uwsgi as a background process and binds to TCP port 9001 on all interfaces. I’ll probably write an upstart script to deal with this at some point, but this is working well at the moment. That’s really all you need to do to run the uwsgi server. If that’s all you wanted, then you’re done, but you probably still need to setup a method to pass uwsgi requests to the uwsgi server. Here’s how you do it with nginx:

server {
  listen 80;
  root /var/www/;
  location /static/ {
    root /var/www/;
  location / {
    uwsgi_param  UWSGI_SCRIPT  badtranscript.deploy.wsgi;
    include      uwsgi_params;