Long time spent issuing the network request on file upload

I am doing an AJAX HTTP post request to upload an image blob to my droplet. The file uploads fine, but the time spend issuing the network request is incredibly long.

The time spent issuing the network request for a 3.9MB image is anywhere from 20 to 30+ seconds while the time spent processing the image on the server is only about 3-4 seconds.

If I repeat the same process, but point my request to a locally hosted server, the time spent issuing the network request for the same 3.9MB image is 84ms while the time spent processing the image on the local server is only 2.4 seconds.

Why does it take so much longer to issue the network request to the remote droplet?


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

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.

Hi @thechurchconnectory,

The wait time depends upon a couple of things which I’ll try and actually brake them down.

  • Droplet dependency - This is the time from when the request was sent by the client until it first starts receiving the response. Assuming you’re not on a really slow network connection or one with really bad latency (like a satellite link), this is pretty much all about how long it takes the droplet to respond to the request.

  • If only this ajax call is this slow, then there is probably some sort of “startup” time on the droplet. If this is a busy droplet or heavily enforced server, then it could be that your app is swapped out of memory or the cache is empty and it takes a longer time to get your app up and running and ready to start processing the response. Having said that, this might be more common in a shared hosting environment rather than in your dedicated Droplet.

  • It could be that the PHP engine used by the web server has some startup time or the web server has to load something before it can start processing PHP requests and that initialization takes a bunch of time.

Regards, KDSys