Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Long waiting (TTFB) time for scripts / styles on Azure Website

I have this intriguing problem on Azure Website. My website uses 4 script files and 3 style files, each minified. They are not so big, bigest has near 200 KBs. Website had already started. Azure's Always On option is turned on. When I call to WebApi for data it returns in <50ms.

Azure website scripts/styles loading time

And when app is reloaded it needs 250 ms just to get first byte from tiniest script, and others needs much more. Initial Html is loaded in 60 ms. Scripts/styles are cached so they are not downloaded, but the TTFB time is killing the performance. This repeats every single reload. App is not containing any sophisticated configuration so it should run much faster than it.

What can cause such problems?

like image 917
Radosław Maziarka Avatar asked Oct 14 '15 20:10

Radosław Maziarka


2 Answers

Although your static files are cached, the browser still issues requests with if-modifies-since header (which results in a 304).

While it doesn't need to download the actual content, it still needs to wait the RTT + server think time to continue.

I would suggest two things:

  1. Adding Cache-Control and Expire headers - will help avoid 304 in some cases (pretty much unless you hit F5)
  2. Using a proper CDN - such as Incapsula or others, that will minimize the RTT + think time. It can also be used to easily control cache settings for various resources.

More good stuff here.

Good Luck!

like image 121
ZigZag_IL Avatar answered Nov 20 '22 06:11

ZigZag_IL


From here:

As you saw earlier, IIS 7 caches the compressed versions of static files. So, if a request arrives for a static file whose compressed version is already in the cache, it doesn’t need to be compressed again.

But what if there is no compressed version in the cache? Will IIS 7 then compress the file right away and put it in the cache? The answer is yes, but only if the file is being requested frequently. By not compressing files that are only requested infrequently, IIS 7 saves CPU usage and cache space.

By default, a file is considered to be requested frequently if it is requested two or more times per 10 seconds.

So, the reason your users are being served an uncompressed version of the javascript file is because it didn't meet the default threshold for being compressed; in other words, the javascript file was not requested 2 times within 10 seconds.

To control this, there is one attribute we must change on the <serverRuntime> element, which controls compression: frequentHitThreshold. In order for your file to be compressed when it is requested once, change your <serverRuntime> element to look like this:

<serverRuntime enabled="true" frequentHitThreshold="1" />

This will slightly impact your CPU performance if you have many javascript files that are being served and you have users quite often, but likely if you have users often enough to impact CPU from compressing these files, then they are already compressed and cached!

like image 44
CC Inc Avatar answered Nov 20 '22 07:11

CC Inc