Question

Slow content download speed of static files using DigitalOcean droplet and Nginx

Once in a while I’m seeing requests for static files (including JS and images) being made to my web service that have extremely slow content download times. For example, over 60 seconds for a 1.8MB file:

enter image description here

Without making any configuration changes, a subsequent request (hard refresh, not using browser cached files) is pretty reasonable:

enter image description here

I know there will be some variation in content download time due to factors such as TCP packet retransmissions, but I can’t really imagine a difference this substantial (e.g. 1.1min vs 551ms for the tinymce.js file) being caused by packet retransmissions under normal network conditions. Typically it’s about 1/20 requests that are this slow.

Making a request using cURL, I can see that the average download speed is 60062 bytes/sec.

~/test $ curl 'https://example.com/js/tinymce.js?id=a28f73c840cadf0e33ab2735a17c2058' \
  -H 'authority: example.com' \
  # other headers that don't matter right now
  -H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36' \
  --compressed > test.js
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 1789k    0 1789k    0     0  60062      0 --:--:--  0:00:30 --:--:-- 62621

However, the next request of the same file only takes about a second:

~/test $ curl 'https://example.com/js/tinymce.js?id=a28f73c840cadf0e33ab2735a17c2058' \
  -H 'authority: example.com' \
  # other headers that don't matter right now
  -H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36' \
  --compressed > test.js
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 1789k    0 1789k    0     0   984k      0 --:--:--  0:00:01 --:--:--  983k

The server I’m using is a DigitalOcean droplet with 2 dedicated vCPUs (not shared) and 4GB RAM.

I’m running a PHP application using Nginx, and the static files being requested by clients are being served from the public directory of my application.

For Nginx I have:

sendfile on;
sendfile_max_chunk 512k;

and I’m using gzip.

Currently these slow speeds make the web application unreliable for clients.

The DigitalOcean droplet I’m using is in NYC1 (most clients are in that area) and I’m currently making requests from the west coast of North America. I’ll be setting up a CDN soon, but even in the case of a cache-miss the (periodically) slow download speed would make most people leave, so it’s a bit of an issue especially since some of these resources are block rendering of the UI until they’re completely downloaded to the client.

Happy to provide any additional information that would help troubleshoot – or is this big variance in download times just a limitation and expected when using a shared data center?


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