28

In the last couple of weeks we've been investigating some performance issues where our MVC application was responding very slow for the first request. We are talking like 30-45 seconds for the first request and 3 seconds for each new view. Our MVC application is using our OData API (Web API) which is located on the same server. Besides the same performance issues as the MVC application, the first query to entity framework version 6 is executing in 6 seconds and new queries is executing 200ms slower than subsequent queries.

In order to meet our requirements, we have chosen to execute all known Ef queries and hit all our MVC/API endpoints from Application_Start in Global.asax. This seems to work fine for at least a couple of hours, but after some time without use, the first request to every MVC view is responding in 3-5 seconds.

We have configured the websites to be "Always on" and we have not found anything in the IIS logs or the logging we've added to Application_Start. So it seems our applications are at least not recycling. I suspect some kind of IIS cache being cleared or maybe some Ef cache? Any suggestions are welcome.

Kasper Nørtoft
  • 291
  • 1
  • 3
  • 4
  • 1
    A quick work around can be to create a background Job that will ping you website frequently to avoid the idle state of the webApp. – Dev Mar 20 '16 at 16:02
  • Could you resolve your issue? We are having the same issue with our MVC app beeing slow on the first request after inactivity. Even though "Always on" is enabled. According to the log we are writing on Application_Start the application doesn't restart so it must be something else... :( – TS. Jan 23 '17 at 10:09
  • It seems our problem is EF query compilation on Azure websites. We got a couple of .Includes queries on most our API endpoints which our MVC app is consuming. It seems to take up to 1 seconds for each query compilation which is a long time. So far we have setup a temporarily polling service so the query compilation takes place before our customers hit our website. – Kasper Nørtoft Jan 26 '17 at 10:11
  • As of Dec 2019, shooting GET requests every 15 seconds also does not work. – Anoyz Dec 06 '19 at 10:46
  • I am also facing the same issue. Found this link, not sure if this solution will work. https://medium.com/tryce-technologies/possible-fix-when-always-on-azure-web-site-is-sometimes-slow-to-load-79ddd606f6cf – Emran Hussain Jun 10 '20 at 02:18

4 Answers4

16

You'll want to enable the "Always On" setting for your web app.

You can do that from portal.azure.com -> your site's blade -> Configuration -> General Settings -> Always On

See here for details: https://azure.microsoft.com/en-us/documentation/articles/web-sites-configure/

When Always On is disabled, after 20 minutes of inactivity the site gets taken down in order to free up resources for any other sites that might be running on the same App Service Plan.

Gangula
  • 5,193
  • 4
  • 30
  • 59
Zain Rizvi
  • 23,586
  • 22
  • 91
  • 133
  • Does increasing session time out will help the website being alive? – Aditya Bokade Sep 24 '16 at 17:15
  • @AdityaBokade no, it doesn't have any effect – Zain Rizvi Sep 26 '16 at 17:55
  • "We have configured the websites to be "Always on"" – EscapeNetscape Nov 02 '16 at 11:58
  • 8
    I too found that Always On does not help with the issue. I clearly see in web server logs that it is being pinged with AlwaysOn requests, but still it often takes about 40 times to log into my site after long periods of inactivity. I have to investigate, though, maybe the problem is not "cold start" but something entirely else. – JustAMartin Feb 23 '17 at 07:41
  • 2
    Always On didn't solve the issue here. Anyone else found any solution? – Anoyz Dec 06 '19 at 10:47
14

I've been having the same problem and unfortunately the "Always On" setting is not available on the free and shared pricing tiers. I found an easy way of keeping the Web App warm so it doesn't unload. The trick is to set up an Application Insights ping test on a 15 minute interval against the Wep App URL. A walkthrough on how to that can be found here

Gangula
  • 5,193
  • 4
  • 30
  • 59
JayChase
  • 11,174
  • 2
  • 43
  • 52
  • 1
    Great suggestion. – rollsch May 26 '17 at 05:22
  • I manually scripted a GET request every 15 seconds on my machine, and it still doesn't solve the issue. Is your proposed solution significantly different from that? – Anoyz Dec 06 '19 at 10:49
  • @Anoyz It is just a ping test so I can't see there would be a difference but there are lots of config options for testing from multiple locations etc. that might make it a more reliable method. – JayChase Dec 06 '19 at 11:10
  • My free App service says `Application Insights is not supported for your app's runtime configuration`. Anyone knows which runtime, OS or public stack is supported? – Gangula Jan 24 '22 at 16:32
1

A quick work around can be to create a background Job that will ping you website frequently to avoid the idle state of the webApp.

Or

Try to upgrade the Sql Server db plan & test accordingly.

Good luck & hope this helps.

Dev
  • 410
  • 5
  • 23
0

Did you try to investigate this issue by enabling failed request logging?

Azure Portal → your app service → Monitoring → Diagnostics logs → Failed request tracing (On)

I experienced a similar issue that was caused by limiting access to the application using the ipSecurity section in web.config. If you happen to restrict access this way, you need to whitelist the IP of your app service.

tilo
  • 14,009
  • 6
  • 68
  • 85
  • I experience same issue. Always On is on, IP addresses are whitelisted and Always On pings are properly logged. And still after some time of inactivity the first request takes long time. Even more, few first requests are slow. Then all is fine and after 20 - 30 requests all slows down again to start working as it should. – Megrez7 Jun 16 '17 at 21:27
  • 1
    Did you check your failed request logs again? It seems as if the AlwaysOn request now comes from `::1` (IPv6 for 127.0.0.1) instead of the IP of the app service. – tilo Jun 27 '17 at 07:10