How to make Django requests faster

My app runs on DO Ubuntu droplet, using django + gunicorn + nginx. What it basically does is when somebody loads the page, it makes a lot of requests to third-party API(which is very fast). It is supposed to make ~300 requests in several seconds(how it works on my local computer), but now I tried it with just 30 request and it already takes 6 seconds. How can I speed it up?

I use requests library. I tried multiprocessing to parallelize the code, but it says that I have only one CPU on DO. Moreover I took a look at stats and found out that it takes only ~0.01 Mbps so it’s not DO restriction.

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.

6 seconds to load a page making 300 requests to a 3rd party service isn’t too bad. If there is any way you can reduce these requests I would recommend it as this isn’t a very scalable and efficient setup.

In the short term, is this an application that would benefit from caching. You can use either a 3rd party service like CloudFlare or create your own proxy with nginx. This should reduce the number of requests your server needs to make.