0

Recently we want to cater the slow loading problem of IIS for first request, after I did some research, I've found that IIS7.5+ has a feature named "Application Initialization" which maybe what I need.

However I have to understand the mechanism before I try to apply it and here is my understanding:

With default IIS setting:

  1. The application pool idle after 20 minutes
  2. The corresponding worker process is killed
  3. First request comes in
  4. IIS starts to create a new worker process
  5. IIS starts to load the application
  6. The client can see after application is loaded

And step 4, 5 makes first request not so responsive.

With Application Initialization set:

  1. The application pool idle after 20 minutes
  2. The corresponding worker process is killed
  3. IIS starts to create a new worker process
  4. IIS starts to load the application through a "fake" request
  5. First request comes in
  6. The client can see after application is loaded

Now the first request is responsive as indeed it is not the first request to the server, sometimes before there was a "fake" request which kicks loading of the application.


What I would like to know is that:

Is my understanding correct?

When application initialization is set, the worker process is still being killed, but a new one is created right after it, is it the case?

shole
  • 4,046
  • 2
  • 29
  • 69

2 Answers2

2

That's pretty much how it works. Without Application Initialization, as you mentioned, once the worker process is killed, it is not restarted until a request is sent to it. Upon the first request, a new worker process (W3WP.exe) is started and it starts to load the application. And this cold start of the application is what typically makes the first request less responsive. For eg. if it's an ASP.NET application, the first request triggers the recompilation of the temporary ASP.NET files and this can take several seconds in a moderately large enterprise application.

If you look at the setup of Application Initialization, you will see that there are two main parts to it:

  1. You need to set the startMode of the application pool associated with the website to AlwaysRunning
  2. You need to set preloadEnabled to true on some path (path to the website) on the ApplicationPool

Step 1 is what tells IIS to automatically restart the IIS worker process whenever there is a reboot or IISReset. (You can easily see this in action in TaskManager - do only step 1 and do an IISReset, you should be seeing the existing W3WP.exe process getting removed and a new one is getting created)

Step 2 is what tells IIS to make the initial fake/dummy request that will do all the required initialisation of your web application. For eg. for an ASP.NET application, this essentially will trigger the compilation of all the ASP.NET files, so that the next request - the actual first request to the page does not experience the long delays associated with app initialisation.

While it is true that a traditional approach of keeping using a script to poll the app to prevent it from going idle can do the job, the ApplicationInitalization module makes the job much easier. You can even have IIS issue the dummy request to a custom warmup script that does much more than a simple page load - preloading a cache of several webpages, ahead of time generate/do any task that might otherwise take longer etc.

Official documentations here:

IIS 7.5

IIS 8.0

jester
  • 3,491
  • 19
  • 30
1

Your understanding is correct based on my experiences. I first ran into this capability in a performance testing scenario way back in 2014. I was custom coding the ping portion of this into monitoring jobs :O

"The Application Initialization Module basically allows you to turn on Preloading on the Application Pool and the Site/IIS App, which essentially fires a request through the IIS pipeline as soon as the Application Pool has been launched. This means that effectively your ASP.NET app becomes active immediately, Application_Start is fired making sure your app stays up and running at all times." - Rick Strahl

Official detailed docs are on the MSDN site, from what I see not much has changed between IIS 7.5 and 8.0 in the way of config.

Paul Bruce
  • 554
  • 2
  • 7