How to make Django requests faster

April 28, 2018 667 views
Django DigitalOcean Ubuntu 18.04

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.

1 Answer

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.

Have another answer? Share your knowledge.