Feed Sign in with OpenID OpenID

Simon Willison’s Weblog

How to use Django with Apache and mod_wsgi. My favourite deployment option is now included in the official Django docs, thanks to Alex Gaynor. I tend to run a stripped down Apache with mod_wsgi behind an nginx proxy, and have nginx serve static files directly. This avoids the need for a completely separate media server (although a separate media domain is still a good idea for better client-side performance).

Tagged , , , , , , ,

9 comments

  1. I used to choose apache and mod_python as the container fo django, but the performance is quite poor. How 's the wsgi doing?

    rates - 1st April 2009 07:47 - #

  2. mod_wsgi is much faster.
    The best option for speed is fapws2 or fapws3 (uses different event library). With fapws3 you don't need nginx actually.

    Nick - 1st April 2009 07:53 - #

  3. I prefer nginx backed by nginx/mod_wsgi. I've gotten faster benchmarks (5-10%) than apache, and it's far easier to deploy. Apache/mod_wsgi has a broader range of configuration options available, but most of them aren't needed in my setups..

    Johan - 1st April 2009 08:20 - #

  4. Can you expand a little on that. Why does a separate media domain affect client-side performance? Do browsers cache a limited amount per a domain?

    DFan - 1st April 2009 10:40 - #

  5. Simon, but nginx *is* a completely separate media server :-).

    Not that there's anything wrong with it...

    Ivan Sagalaev - 1st April 2009 11:40 - #

  6. DFan: Most browsers will only open a maximum of two connections to a domain at a time, which slows down parallel loading of assets. See here for more details:

    http://yuiblog.com/blog/2007/04/11/performance-res earch-part-4/

    Ivan: I agree, but the advice in the Django docs tends to suggest running a completely separate media server on a separate IP address (since you can only have one web server bound to port 80). By proxying through nginx you only need one web server running on port 80 (I run the Apache/mod_wsgi on a higher port).

    Simon Willison - 1st April 2009 12:14 - #

  7. Interestingly, I tested a very simple python application which used a local db with mod_wsgi (embedded) and mod_python yesterday and got very similar results:

    1673 reqs/s for mod_wsgi
    1387 reqs/s for mod_python
    896 reqs/s for FastCGI with flup (standalone mode)

    I tuned up the Apache server for Python using http://blog.dscpl.com.au/2009/03/load-spikes-and-e xcessive-memory-usage.html

    Note, Graham suggests the daemon mode however (the Django docs doesn't say but the mode is embedded by default) for permission reasons. The results could have been different a little then.

    Are you running mod_wsgi in the daemon mode?

    Jiri Barton - 1st April 2009 14:55 - #

  8. Compare to fapws3 5565.03 req/s for simple Django page. http://william-os4y.livejournal.com/6264.html

    Nick - 1st April 2009 16:07 - #

  9. Nick, that's a nice number, but I don't see where, on that page, it says the 5565 req/s is for Django. In particular, CherryPy is mentioned on that page as being significantly slower, and in general, I think CherryPy is simpler (and faster because of this) than Django.

    In any case, speed in web servers will very easily be dominated by duration in dynamic rendering-- I know my views are glacial compared to the time it takes even sad old mod_python to get around to shipping me some bits.

    FWIW, we're using mod_wsgi, but took a serious look at nginx at one point.

    Jeremy Dunck - 1st April 2009 21:15 - #

Comments are closed.
A django site