Benoît Chesneau: Gunicorn, django and wsgi

Tags: django, djangocon

Benoît is Gunicorn’s author.

WSGI (see yesterday’s talk on python 3 and wsgi) is the gateway between a web server and a python application. An actual WSGI call is pretty simple.

The main usage of WSGI for Django is as a way to deploy your Django apps. Other things you can think about:

  • Why reinvent the wheel? Combine Django, in the same site, with other wsgi-capable applications. For example, with wsgi you can easily hook an existing mercurial interface into your application.

  • Common middleware. There are a number of common “wsgi middleware” products that provide non-django-specific functionality that we can however use just fine.

Deploying inside a web server: there are basically two choices:

  • uWSGI for NGINX. Fast.

  • mod_wsgi for apache. Also fast, but not so fast as uWSGI. Really easy to install, it is included in all Linux distributions. (apt-get install libapache2-mod-wsgi).

An alternative is to run a wsgi server.

  • Spawning, Paster.

  • Cherrypy. Pretty stable.

  • Gunicorn.

Ruby’s Unicorn is pretty awesome. It is used by github, for instance. He needed something stable and something simple: for python. So gunicorn (“green unicorn”, a kind of rat snake) was born. Philosophy: simple, minimal, performant, unix. It is performant; for instance Sweden’s largest blog provider http://blogg.se uses it.

Gunicorn allows you to send signals (“kill” command on linux) to the process. Not only for restarting itself, but even for increasing or decreasing the number of worker processes. All without losing connections (one of the initial design goals).

There are tuning tips for gunicorn and your os at http://gunicorn.org/tuning.html .

Monday night dinner
 
vanrees.org logo

About me

My name is Reinout van Rees and I work a lot with Python (programming language) and Django (website framework). I live in The Netherlands and I'm happily married to Annie van Rees-Kooiman.

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):