Arrow of time
Arrow of time

What Django caching can do

Share Tweet Share

Nothing special here, just wanted to make a note about how simply turning on Django caching can bring a site's …

Nothing special here, just wanted to make a note about how simply turning on Django caching can bring a site's performance up from this:

Server Software:        nginx/1.2.1
Server Hostname:        vo.ivoras.net
Server Port:            80

Document Path:          /api/location/1
Document Length:        530 bytes

Concurrency Level:      16
Time taken for tests:   7.683 seconds
Complete requests:      1000
Failed requests:        0
Total transferred:      703000 bytes
HTML transferred:       530000 bytes
Requests per second:    130.16 [#/sec] (mean)
Time per request:       122.922 [ms] (mean)
Time per request:       7.683 [ms] (mean, across all concurrent requests)
Transfer rate:          89.36 [Kbytes/sec] received

to this:

Server Software:        nginx/1.2.1
Server Hostname:        vo.ivoras.net
Server Port:            80

Document Path:          /api/location/1
Document Length:        530 bytes

Concurrency Level:      64
Time taken for tests:   15.846 seconds
Complete requests:      10000
Failed requests:        0
Total transferred:      8390000 bytes
HTML transferred:       5300000 bytes
Requests per second:    631.06 [#/sec] (mean)
Time per request:       101.416 [ms] (mean)
Time per request:       1.585 [ms] (mean, across all concurrent requests)
Transfer rate:          517.05 [Kbytes/sec] received

This is Django 1.7 on uwsgi (2 worker processes, threaded) on nginx on a budget single-core VPS on a Xeon X5670 from 2010. No cache tuning has been done, this is bog-standard, simple Django per-view in-memory cache, set on this single view. Note the Django performance increase from 130 pages/s to 631 pages/s, or around 4.8x. Python is one of the slowest languages available, but a prudent use of caching can hide this so well that it can make it seem like you can deliver 10.000+ pages/s on reasonable modern hardware.

Cheers!


comments powered by Disqus