Reputation: 4292
I've been having some trouble experiencing delays in how quickly a download starts in the browser (not the download speed, but the time taken between clicking the download link, and the download appearing in the browser).
I've simplified my code as much as possible;
$filepath = $this->_resourceFile;
ob_start();
$start = microtime(true);
readfile($filepath);
$end = microtime(true) - $start;
Mage::log('Time taken to serve file was '.$end);
(You'll see this is part of Magento, I've heavily edited the way Magento was serving downloadable product files to try and speed things up. This has worked for the majority of cases, but I'm still experiencing issues)
The logging I've placed has shown the below;
2014-10-23T14:19:15+00:00 DEBUG (7): Time taken to serve file was 0.067724943161011
2014-10-23T14:24:48+00:00 DEBUG (7): Time taken to serve file was 0.069678068161011
2014-10-23T14:25:58+00:00 DEBUG (7): Time taken to serve file was 0.080054998397827
2014-10-23T14:26:28+00:00 DEBUG (7): Time taken to serve file was 0.067059993743896
2014-10-23T14:27:27+00:00 DEBUG (7): Time taken to serve file was 0.068262100219727
2014-10-23T14:30:08+00:00 DEBUG (7): Time taken to serve file was 0.066760063171387
2014-10-23T14:36:34+00:00 DEBUG (7): Time taken to serve file was 90.616213083267
2014-10-23T14:45:11+00:00 DEBUG (7): Time taken to serve file was 0.065201997756958
2014-10-23T14:45:22+00:00 DEBUG (7): Time taken to serve file was 0.073112010955811
2014-10-23T14:46:56+00:00 DEBUG (7): Time taken to serve file was 87.481207132339
2014-10-23T14:47:44+00:00 DEBUG (7): Time taken to serve file was 36.195640087128
2014-10-23T14:47:48+00:00 DEBUG (7): Time taken to serve file was 0.067437887191772
2014-10-23T14:48:01+00:00 DEBUG (7): Time taken to serve file was 0.068021059036255
2014-10-23T14:48:06+00:00 DEBUG (7): Time taken to serve file was 0.028129100799561
2014-10-23T14:48:13+00:00 DEBUG (7): Time taken to serve file was 0.067390918731689
2014-10-23T14:49:00+00:00 DEBUG (7): Time taken to serve file was 0.065808057785034
2014-10-23T14:49:06+00:00 DEBUG (7): Time taken to serve file was 0.06847882270813
2014-10-23T14:49:48+00:00 DEBUG (7): Time taken to serve file was 0.063234090805054
2014-10-23T14:50:03+00:00 DEBUG (7): Time taken to serve file was 0.059723138809204
2014-10-23T14:50:08+00:00 DEBUG (7): Time taken to serve file was 0.068203926086426
2014-10-23T14:50:13+00:00 DEBUG (7): Time taken to serve file was 0.065500974655151
2014-10-23T14:50:16+00:00 DEBUG (7): Time taken to serve file was 0.064054012298584
2014-10-23T14:50:20+00:00 DEBUG (7): Time taken to serve file was 0.068597078323364
2014-10-23T14:50:24+00:00 DEBUG (7): Time taken to serve file was 0.026658058166504
2014-10-23T14:51:47+00:00 DEBUG (7): Time taken to serve file was 0.065510988235474
2014-10-23T14:51:56+00:00 DEBUG (7): Time taken to serve file was 0.06929087638855
2014-10-23T14:52:00+00:00 DEBUG (7): Time taken to serve file was 0.026684999465942
2014-10-23T14:52:32+00:00 DEBUG (7): Time taken to serve file was 0.067147016525269
2014-10-23T14:55:55+00:00 DEBUG (7): Time taken to serve file was 0.067998886108398
You'll see that amongst the 0.06...'s there's a 90 second wait, 87 second wait, and a 36 second wait. What could be causing these spikes?
The site is running on a Linux server, with apache and nginx, with PHP5.3.3. Could it be a server load issue? Am I right in thinking a users bandwidth should have almost nothing to do with this delay?
Upvotes: 2
Views: 176
Reputation: 4292
So, after much investigation it appears it was a server issue.
The server stores the file in RAM the first time its accessed, to speed up the access in the future. It was the time taken to copy the file into RAM that was causing the delay - once the file was in RAM it was served immediately.
We've altered IO resource settings on the server and the initial download time is now down to 6 seconds, rather than 90.
Upvotes: 1