Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC website on Azure super slow on first load of each page

I'm having a major issue with performance on an MVC site we are developing. When the site is hosted in Azure, the rendering phase of views takes a huge amount of time the first time a page is loaded, we're talking 15-60s per page. Subsequent loads of the same page thereafter are nice and fast, as one would expect. This is a trace from Glimpse for a hit on a page for the first time:

enter image description here

As you can see from the graph, the Razor rendering seems to be the main offender. I've read lots of things about pre-compilation of Razor views and I've tried implementing this but it made no difference for us at all. I'm also engaging with the Azure Web App devs who pointed fingers at Glimpse being an issue, but I've tried the app without Glimpse installed and it's still as slow as usual.

I'm getting pretty stuck here...any ideas?

like image 831
James Avatar asked Sep 23 '16 15:09

James


2 Answers

I found a solution for faster startup time of MVC apps, most notable on Azure App services. The trick is to precompile the views, so App services doesn't have to do that for every view that is needed at the time of the request.

The summary of my findings:

Add this to the MSBuild arguments and you'll have a ASP.NET MVC 5 that will start up faster and every new page will load faster.

/p:PrecompileBeforePublish=true /p:UseMerge=true /p:SingleAssemblyName=AppCode

More information can be found here: http://blog.deltacode.be/2017/01/08/fix-slow-startup-of-asp-net-mvc-5-on-azure-app-services/

like image 128
David De Sloovere Avatar answered Nov 03 '22 20:11

David De Sloovere


Is it the first time loading each page, or the first time hitting the site after inactivity?

The IIS takes a while to boot up after you upload new files to the app container. So the first page hit after you've updated the app will be slower. Also Azure Web Apps get dehydrated after a period of inactivity. This also causes the first page hit to be very slow if the page hasn't been accessed in a while.

To combat this, in the Application Settings for the web app, you can find a setting called Always On, which basically pings your page every couple minutes to keep the app hydrated and responsive.

like image 34
Sentri Avatar answered Nov 03 '22 18:11

Sentri