Frank Wiles talks about things he sees as a consultant: small easy changes that can make a huge difference. As an illustration, he made a sample app and filled it with quite a lot of data to get some proper measurements out of it.
Measurements were made with siege A
baseline check was between
DEBUG=False, the difference
was 17 versus 120 requests per second.
You can tell django to cache templates. The cached loader gave 140 instead of 120/second.
Cached sessions: normally every request means a database hit to get your session. Normally the session isn’t even really used to store data. You can get them from the cache just fine in those cases. No need to store empty unused sessions, right?
SESSION_ENGINE to the cached version and this one configuration
line changes got him from 120 to 155 req/sec.
Since django 1.6, cached database connections are easy to use. The default
is off, so set
CONN_MAX_AGE to some value and you can get 25%
Are you using all of your machine? How many cores do you have? How many gunicorn processes do you have? Or do you have too many processes? 2 processes on an 8 core machine doesn’t utilize it fully. 16 processes on an 8 core machine hoses it.
You can often optimize other things than django. nginx for instance:
This was another 13% improvement!
Combine CSS and JS. Not doing it costs so much time. With many css/js files, half a second per page is typical. Use django-compressor or django-pipeline for instance.
What also really really helps: far future expire headers on your static files. Note: it doesn’t actually have to be that far in the future. 5 minutes is often enough. Most people only look at your site for a few minutes at most, right?
Why would you go through the effort? It could save you 10% in hosting costs. But perhaps that doesn’t convince you. So: do it for django. Optimize even your own small blog. Sites made with django should be speedy!
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.
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):