22

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?

54

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

  • 3
    Comments on drawbacks to these settings would be appreciated. Surely there's a reason they aren't defaults. – user42134 Mar 2 '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 2 '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 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
  • 1
    FYI for folks using this: the applicationInitialization goes into <configuration><system.webServer> – Paul Apr 20 '18 at 15:32
1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.