30

I am running an ASP.NET MVC webapp in IIS 8.0. My application needs to be warmed up before taking requests. We already have a process to warm up the application automatically when we deploy new code. However, we are seeing periodic App Pool Recycle events that are resulting in the app not being warmed up.

Is there a best practice for detecting an app pool recycle event and executing a script or some code?

AgileJon
  • 425
  • 1
  • 5
  • 9

2 Answers2

61

There are several things you can do:

1. Application Initialization

You can use Application Initialization Module which comes in-box with IIS 8.0

you can have something like this in your web.config

<applicationInitialization
     doAppInitAfterRestart="true" >
   <add initializationPage="/" />
</applicationInitialization>

This will send a request to the root of your app (initializationPage="/") every time your app starts automatically.

You can also configure the Start Mode for your application pool to Always Running which means every time IIS restarts, it will make sure to start your application pool immediately (this if from right click on your application pool then Advanced Settings

enter image description here

and Preload for your site itself (right click on the site then Manage Site then Advanced Settings

enter image description here

2. Disable Idle Time-out

Additionally you can disable idleTimeout (by default IIS will shut down the app after 20 minutes of in activity) by changing the of in Idle Time-out for your application pool to 0 (infinite)

enter image description here

3. Disable periodic recycling

also turn off Regular Time Interval (minutes) by default IIS would recycle your app every 29 hours.

enter image description here

For

ahmelsayed
  • 831
  • 7
  • 3
  • 4
    Comments on drawbacks to these settings would be appreciated. Surely there's a reason they aren't defaults. – user42134 Mar 02 '15 at 15:01
  • 2
    Sure, high memory consumption if you run multiple sites on the same IIS box since all the sites stay alive all the time, which leads to very low site density. Also no protection against memory leaks in your applications. Keep in mind that IIS was around before managed languages became popular for web and many apps were running native handlers that got into memory leaks & weird state if left running for a long time. That was done to help sysadmins who had to wake up in the middle of the night to reset servers due to app issues. They are still defaults mostly for backward comparability reasons – ahmelsayed Mar 02 '15 at 18:07
  • 1
    Alternatives in ***IIS 7.5 - Windows Server 2008 R2*** ? – Kiquenet Jul 21 '15 at 11:44
  • 2
    You can get the [Application Initialization Module](http://www.iis.net/downloads/microsoft/application-initialization) for IIS 7.5 for #1 to work. #2 and #3 are applicable as-is to IIS 7.5 – ahmelsayed Jul 21 '15 at 19:44
  • @ahmelsayed Thanks I did everything but still not calling `applicationPage` on one server, any idea? https://superuser.com/questions/1246478/iis-applicationinitialization-doesnt-call-initializationpage-on-one-of-the-serv – Reza Sep 01 '17 at 13:18
  • 2
    FYI for folks using this: the `applicationInitialization` goes into `` – Paul Apr 20 '18 at 15:32
  • Is the path for the application initialization relative to the root directory? In other words, if the application lives in a virtual directory named: /mypath Should the value be "/mypath" or "/"?? – LarryBud Mar 27 '20 at 20:40
2

From my experience, AlwaysRunning and Preload enabled doesn't get much speed up. The most wait time goes on dynamic compilation (which can be fixed with aspx precompile) and loading assemblies into memory and caching.

zmikic
  • 21
  • 1