Question

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

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.

Show comments

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

@404namenotfound My guess was that TFFB was heavily affected by using an Amazon hosted database but having everything else hosted at DigitalOcean. I wasn’t prepared to migrate the database to DigitalOcean at the time so I had a mix of the app/sever running on DigitalOcean but the database was on AWS. Because of time constraints, I gave up and basically cloned my exact DigitalOcean ubuntu OS configuration to an AWS EC2 nano instance and everything came right. Perhaps if I went all-in on DigitalOcean I could have avoided a high TTFB too.

My video is based on a compilation of the most important DO tutorials, including security and configuration. It is possible that my Nginx configuration is better prepared for a real case. Or it may, that a small syntax error is causing this slowness. I guess you’ve replaced HTML5 + PHP with HTML5 + Python. You should observe the browser’s command console (F12) and that there is no error. Have you contacted DO support?