Question

We are trying to optimize our ASP.NET MVC app and get a big time difference between our server side logs and client side delay.

When refresh the page in Chrome in Timeline it shows 4.47s:

enter image description here

As I understand from the picture, the time for server side code execution should be 3.34s, but in our server logs we have the following:

  • Begin Request 15:41:52.421
  • End Request 15:41:53.218
  • Pre Send Request Headers 15:41:53.218
  • Pre Send Request Content 15:41:53.218

So, according to server side logs code execution took only 797ms in total. It does not happen all the time and very often the Chrome timeline shows times very close to server logs. But sometimes we have this couple of seconds delay.

Where could this delay come from?

Was it helpful?

Solution

There is lot of stuff that can affect the time sporadically to such an extent, even though addition of almost three seconds is sort of excessive for this scenario. Since you don't mention much about how is your network set up, what operating system u use etc, I'll try to sum up a list of what comes to my mind when dealing with this sort of a delay, sorted by probability.

The main problem here is the Waiting part of the total time there you should concentrate your detective talent.

Please note that the answer is very general since the question says virtually nothing about configuration of the server, client computer or the network (if any) between them. Since you say the delay is not present all the time, there are one or more moving targets you need to aim at.

Antivirus If you have an internet shield or similarly named component, it is not uncommon that the antivirus can seemingly randomly delay some connections while leaving other virtually untouched. For the browser this is transparent (it's just a delay, whatever may have caused it), hence the Waiting.

Network issue Especially if you are connected through a wireless network or poorly configured wired network, a few seconds delay may occur even though the label on the network device says TurboSpeedTM.

Server side issue Server may be overloaded with previous requests in a manner not covered by your in-application timer, since there are many steps the server performs before and after your script is executed.

Client OS issue Just like the antivirus, the OS can delay your packets virtually randomly for various reasons.

When hunting down such issue, I would recommend trying to perform the query on the server itself and compare resulting times, try as may combinations of network setup and operation systems as possible, prefer well planned network environments to those with many unknown or external factors (read wireless) and make use of some packet sniffing software (like wireshark) to check whether the browser doesn't lie. And that would be just the start of it :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top