How to increase ASP.Net MVC3 performance on each page?

If I make changes in razor mode, recompile, or wait 15-20 minutes, the page may take 3 to 20 seconds to render on the first hit. I understand that the view must be recompiled after the change. I also understand that the application will be unloaded after a period of inactivity, but I thought it would be a one-time penalty for the very first strike. But for me it looks like every page.

Take, for example, my homepage. According to YSlow, this is a “B” with 15 components and a weight of 250K (including a hyperlink with optional jQuery for MiniProfiler). From MiniProfiler, I see about 500 ms on the first line (http: // localhost: 80). I assume this involves compiling the view. But then I see 1200 ms for Find: Index. No SQL calls. The total load time at the first hit is about 3000 ms, subsequent hits are about 40 ms.

On another page with several partial views, the parent view takes 2400 ms for "Find", one of the partial views takes 1000 ms for the search. The parent view also takes 3200 ms for the "Render". And the biggest impact on the first line (http: // localhost: 80 / User / Dashboard), which was a whopping 7000 ms. This page has only 3 requests with a total request time of 100 ms. The total boot time was more than 15000 ms. Subsequent hits are about 250 ms.

Our setup is ASP.Net MVC 3, Ninject, EF4.2, the Razor viewer, ELMAH, NLog, Html5Boilerplate and MvcMiniProfiler. I created a duplicate project and removed Ninject, ELMAH, NLog, and MvcMiniProfiler. Performance was only marginally faster. We have about 15 controllers and about 40 views, all in one area.

Is this normal performance? When we deploy Azure, this is even worse (naturally) than testing locally. Are there any suggestions for improvement?

Edit: The first hit after compiling to IIS / localhost (in release mode and with debug = false compilation) can be about 15 seconds. The Azure deployment running in the version has a faster first hit, but is still in the range of 5-10 seconds. I tried David Abbo's project, but did not see anything dramatic.

+4
source share
1 answer

Do you deploy this app often? If so, then I can understand why the first shock effect can be troubling.

We often deploy and create a separate project to “warm up” our deployments. This is a unit test project that uses WebDriver to run every uncompressed view in our application after it is deployed.

Basically, you just use the WebDriver API to launch the browser, and then move () to each URL that you need to compile. Run it once and the deployment will be warm.

In addition, in Azure, you can disable the idle timeout so that your application never stops. We use this script:

%windir%\system32\inetsrv\appcmd set config -section:applicationPools -applicationPoolDefaults.processModel.idleTimeout:00:00:00 

... and run it during your Azure deployment as follows:

  <Task commandLine="startup\disableTimeout.cmd" executionContext="elevated" taskType="simple" /> 
+2
source

Source: https://habr.com/ru/post/1385573/


All Articles