How to speed up TTFB (django+gunicorn+nginx)
I’m trying to migrate an existing Django web app from AWS (using Apache) to DigitalOcean using nginx.
It’s not an identical comparison, but I’m getting massive differences in TTFB which I can’t account for. For a basic page, I’m getting these stats:
Discovered: 0.010 s
Request Start: 0.258 s
DNS Lookup: 26 ms
Initial Connection: 97 ms
SSL Negotiation: 118 ms
Time to First Byte: 7159 ms
Content Download: 2 ms
Bytes In (downloaded): 4.9 KB
Uncompressed Size: 31.1 KB
Bytes Out (uploaded): 0.5 KB
In comparison to my AWS site which is
Discovered: 0.008 s
Request Start: 0.124 s
DNS Lookup: 27 ms
Initial Connection: 31 ms
SSL Negotiation: 50 ms
Time to First Byte: 579 ms
Content Download: 3 ms
Bytes In (downloaded): 6.2 KB
Uncompressed Size: 34.2 KB
Bytes Out (uploaded): 0.5 KB
I’ve followed the tutorials for:
When that resulted in really slow TTFB I proceeded to
- Enable gzip compression
- Ensure HTTP/2 was used.
- Tried other nginx optimisation tricks
In an attempt to see some of the numbers budge, I moved a lot of asset loading to CDN. It ticked a lot of boxes in https://www.webpagetest.org, but it didn’t alter the TTFB, which is by far the biggest bottleneck.
As you can see a 7s TTFB is absolutely massive! Most users keep mentioning times in the >1s range.
I’m totally stumped for ideas now, so short of nuking my droplet and starting from scratch, I’m not sure what else to try.
Is there something I should double check? I can post some configs if that helps.