1

I have a django site which is ajax intensive currently running on apache mod_wsgi with nginx as a reverse proxy.

Now is it better to retain my current setup or is it better to run my django site on tornado with nginx as a reverse proxy and load balancer?

The reason I'm asking is that I've read somewhere something like mod_wsgi wasn't designed for async stuff. I'm not really sure about that part though but It got me thinking that maybe tornado with nginx will be good for my setup since its non-blocking.

I need your advice. Thanks.

Marconi
  • 199
  • 3
  • 14

3 Answers3

4

Django sits on top of the WSGI interface and that interface is by definition blocking. That you are therefore not using any async mechanisms in your web application, what benefits you get from using an async web server is greatly reduced. Any benefits are going to be more to do with the alternate server being lightweight and not carrying so much overhead and nothing to do with fact that async is used. To get the most from an async server you would need to ditch Django and write to the async APIs of the specific async server you are using.

It should also be highlighted that the initial benchmarks that were released about Tornado in comparison to Django on top of Apache/mod_wsgi were flawed. They claimed that Tornado was 4 times faster. That may have been true for a simple async web application written to Tornado APIs, compared to a Django hello world application, but if you compare it instead to a basic WSGI hello world program, performance isn't that much difference. Thus, performance of Django running on top of Tornado with a WSGI adapter isn't that much different to Django on top of Apache/mod_wsgi and when I tested them on MacOS X, Tornado was actually slower by a little bit.

If you still feel that going with a more lightweight server will bring you some benefits or may be easier to manage, I would suggest gunicorn instead of Tornado.

Graham Dumpleton
  • 5,990
  • 2
  • 20
  • 19
  • Wow that actually cleared what's been bothering me. Its the first time I've heard about Gnunicorn but it looks simple enough. Thanks for clearing things out. – Marconi Feb 12 '11 at 05:55
  • Note that an async web server still matters for serving static content. But this applies to most web severs these days -- nginx and lighttpd are fully asynchronous internally and even Apache 2.4 has an asynchronous mode (event MPM). – intgr Jul 02 '12 at 14:20
1

We use nginx as load balancer and uWSGI as fast WSGI server. So far no problems

alvosu
  • 8,357
  • 24
  • 22
  • Thanks for the info. I have tried nginx + fastcgi and it works great too but I'm more interested on how will my django site perform on nginx + tornado. – Marconi Feb 10 '11 at 16:52
  • 1
    Django and RDBMS are sync. Tornado isn't the best choice. – alvosu Feb 10 '11 at 16:59
1

A great solution to serve Django (or other WSGI apps) actually is Nginx + Gunicorn. So far, this setup works very well, and the Gunicorn software is a recent one with a very good reception by the Python and Django community. You should try it.

I'm currently using supervisord to handle my gunicorn processes but other solutions are possible.

daks
  • 673
  • 6
  • 23