ASP.NET warmup/initialize
Asked Answered
S

2

6

I'm trying to eliminate (or at least minimize) startup/warmup times for my .NET applications. I'm not really sure on how to do this even though it's a common concern.

There's a ton of questions about slow startup of .NET applications. These are easily explained by pool recycles, worker process startup, dynamic compilation of .aspx files, JIT etc. In addition, there are more things that may need to be initialized within the application such as EntityFramework and application caches.

I've found alot of different solutions such as:

However, I'm not entirely satisfied with any of the solutions above. Furthermore I'm deploying my applications to Azure Websites (in most cases) so I have limited access to the IIS.

I know that there are some custom "warmup scripts" that uses various methods for sending requests to the application (e.g. wget/curl). My idea is to create a "Warmup.aspx" page in each of my ASP.NET applications. Then I have a warmup service that sends an HTTP GET to the Warmup.aspx of each site every ... 5 minutes. This service could be a WorkerRole in Azure or a Windows Service in an on-premise installation. Warmup.aspx will will then do the following:

  • Send an HTTP GET to each .aspx-file within the application (to dynamically compile the page)
    • This could be avoided by precompiling the .aspx pages using aspnet_compiler.exe
  • Send a query to the database to initialize EntityFramework
  • Initialize application caches etc

So, my final question is whether there are better alternatives than my "Warmup.aspx" script? And is it a good approach or do you recommend some other method? I would really like some official method that would handle the above criteria.

Any and all suggestions are welcome, thanks!

Sadiesadira answered 7/8, 2012 at 21:14 Comment(3)
Are you taking some measurements so you know what areas you really are trying to optimize? Having applied your changes you can then see the effect. What affect is this having on the end user that you're trying to avoid?Der
I haven't measured exactly but the impact is dependent on how much "warmup" work there is in the application. I see two main "cases" 1) small idle websites with little traffic, these suffer from automatic pool recycles and are always slow (~10 secs) at first request. 2) large websites with many pages that are not precompiled, when doing an upgrade/maintenance or a forced pool recycle - then all the pages are somewhat slow (i.e. 1-3 secs extra) which gives an impression that the application is "sluggish". I won't to avoid both of these problems.Sadiesadira
Pre-compilation definately sounds like it will have maximum benefit in both situations. There are plenty of performance tuning options to consider beyond just the start-up time; technet.microsoft.com/en-us/library/bb727104.aspxDer
V
1

Did you try this IIS Auto-Start feature described here ?

https://www.simple-talk.com/blogs/2013/03/05/speeding-up-your-application-with-the-iis-auto-start-feature/

Vostok answered 10/9, 2013 at 18:14 Comment(1)
Thanks for posting your answer! Please note that you should post the essential parts of the answer here, on this site, or your post risks being deleted See the FAQ where it mentions answers that are 'barely more than a link'. You may still include the link if you wish, but only as a 'reference'. The answer should stand on its own without needing the link.Dubrovnik
D
0

You could have two instances of the site. When you need to deploy a new version, and therefore suffer a startup cycle, remove one instance out of load balancer rotation, deploy and start it, set it in and do the same for instance 2. A rolling deployment.

Donoho answered 7/8, 2012 at 22:15 Comment(1)
Yes, that's a good strategy. My problem is however on how to "start it" as you describe above. When I switch over to the upgraded instance it will be slow, even though I won't have any downtime. Furthermore, I want to avoid the slow startup after idle pool recycles (default 20 min) and forced pool recycles (default every 29 hours IIRC). For manual upgrades/maintenance I can warmup/start it myself by browsing to the site.Sadiesadira

© 2022 - 2024 — McMap. All rights reserved.