Configure the IIS Application Initialization module


During my many years of active IIS administration which hosted ASP.NET application, we had many discussions about why the first request to the web site took longer than those coming after.  In short, it’s because the first request, after a restart of the process results in a recompilation of the temporary ASP.NET files.  In complicated, large scale enterprise applications, the compilation of the temporary ASP.NET files can take seconds.  On one of the system I supported, we actually implemented a process that rotated the responsibility for making the first call to the web site each morning at 6AM to make sure none of our users experienced this.  Sure, you can pre-compile the code but I am talking about long ago, in IT years…

Now that this feature, Application Initialization exists, there is no longer a need for that or anything like it.  Once you recycle or restart the IIS process, a request is sent to the website and the binaries are compiled and ready for fast usages.

To install the feature you can use the Web Platform Installer on IIS 7.5, as shown in Figure 1 or install it as a feature in IIS 8/8.5+.

Figure 1, Install Application Initialization using the Web Platform Explorer

Figure 2, Install Application Initialization using the Install Feature

There is a good set of instruction on how to setup Application Initialization here.  I will cover similar topics, but expand, simplify a little.

After the feature has been installed and you have configured an ASP.NET web site, set the startMode of the application pool associated to the web site in which you want to enable Application Initialization on to AlwaysRunning.  Figure 3 illustrates a method for doing this using the Configuration Editor.

Figure 3, Set application pool to AlwaysRunning

By setting the startMode to AlwaysRunning, when you recycle the process or perform a reboot, the IIS process (W3WP.exe) is started up automatically.  This is not the case by default, where after a restart or reboot, the IIS worker process is not started until a request is sent to it.  Apply these changes and open the Task Manager, you will notice that there is a W3WP process running for the associated web site, even though there has been no request made to it.

To test this feature further, download and install Process Explorer here, find the W3WP process for the web site, open the details window and notice that there is no .Net Assemblies tab.   Figure 4 illustrates this.

Figure 4, Use Process Explorer to view W3WP compiled assemblies, not present

You can also take a quick look at the compiled ASP.NET files which already exist in the C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root directory to set a baseline.  Note: this assume you are using .NET 4 on a 64bit machine. 
You should not see any compiled ASP.NET files for this web site because it has not yet been accessed.

Access the ASP.NET web site and reopen the details windows for the worker process.  You will then see the compiled .NET assemblies, as shown in Figure 5.  This will happen only once and future requests to those ASPX files will be handled from the compiled binary which results in much faster response.

Figure 5, Use Process Explorer to view W3WP compiled assemblies, present

In Windows Explorer, navigate to C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root and see if the ASP.NET file has been compiled…  You can also try matching the names in Figure 5 to the .DLL file.

Next, before executing an IISReset, open Task Manager and locate the PID for the W3WP process of the web site worker process.  When the existing worker process is shut down and a new one created.  Have both a command prompt to enter the command shown in Figure 6 plus the Task Manager and watch the removal of the existing W3WP process and the creation of a new one automatically, it is automatic because startMode=AlwaysRunning.

Figure 6, Execute an IISReset

Up to now, IIS is only configured to start the W3WP worker process for the web site, but the initial request that compiles the ASP.NET files still needs to be configured.  To perform this, make the following modifications and as shown in Figure 7.

  • applicationPool = The name of the web sites Application Pool
  • path = the path to the web site, for example a Virtual Directory
  • preloadEnabled = true

Figure 7, Configure Application Initialization using Configuration Editor

Apply your changes.  To test that everything is working as expected, you can stop the web site configured for Application Initialization and delete the existing ASP.NET temporary files.  Check the Task Manager for a worker process, Process Explorer for any .Net assemblies and restart the web site.  You should see the worker process automatically started, a request being sent to the web site and the .Net assemblies being compiled.

Comments (12)

  1. Anonymous says:

    I've got one question I haven't seen the answer to anywhere. If we configure this setting and then recycle the app pool, will it wait to send traffic to the new worker process until these compilations are done and the site is fully warmed up? The issue I am trying to solve is that we have a few very large websites that take up to five minutes to respond after a recycle, as everything warms back up. I'm wondering if this setting or any other setting would tell IIS to keep using the old app pool until the new one is fully ready?

  2. Hi Jason, there is no code logic that I know of that meets what you are referring to.  When you shutdown the worker process, it will shut down and stop responding to requests.  When the new worker process is started, this feature will make a request and re-compile the binaries.  You might want to look at Process Orphaning and Disable Overlapped Recycle, but there is no way from an IIS perspective to stop requests until the compilation has completed.

  3. JanK-_ says:

    Hi Benjamin,

    your article was very helpful to setup my first Application Inizialization in our recently upgarded webserver. However there is one issue unclear to me: one of our ASP websites uses a custom membership provider. If I see it correct, the pre-loading and pre-compiling cannot access the protected parts of this website, correct?

    At the moment the regarding worker process has about 14 MB after Inizialization, and 100 MB after a website login, so I am assuming that it doesn't completely pre-load. I am wondering if it is possible to also pre-compile those requests users do after login…

    Thanks for any comments on this,

    Jan

  4. Anonymous says:

    Any idea if Application Initialization will ever support sites with requireSSL set to True? This would work wonders on Microsoft CRM but once IFD is enabled, the site is SSL only and can't have a second endpoint thanks to WCF not supporting it.

  5. Anonymous says:

    Will this enable us to fix this kind of problem raised here github.com/…/180

    Actually, we register an automated scheduler job in global.asax.cs. It runs based on the scheduled time. However when IIS recycle happens, it is stopped running till the first request is made.

  6. As of today, I have not seen any updates in regards to this feature.  @JanK you might want to look at aspnet_compiler.exe or other precomplier options.  You can precompile your binaries before deployment.  HTH

  7. Oran says:

    This article claims the Application Initialization Module is available for IIS 7/7.5 via the Web Platform Installer but this is incorrect.  It's only available for IIS 7.5, not for IIS 7.0.

  8. @Oran, fixed that, thanks for pointing it out.

  9. Vikas says:

    Please let me know if Application installation setting pre-Compiles all the binaries or only the requierd ones for the first website hit?

  10. Vikas says:

    My apology ..I meant to ask  if Application Initialization settings do pre-compile all the binaries at once ?

  11. Travis Runyard says:

    You didn't say anything about the developer who screams at you "I can’t upgrade the sites when that setting is on. I now have to manually go through all application pools in production and undo that setting because the upgrade is failing." Can never win in this game.

  12. Sandro says:

    @Travis: Use the app_offline.htm Feature for this.