R – Is IIS Web-Garden Forced Process Initialization possible

asp.netcachingiisweb-garden

We have an ASP.Net Web Application that is running in an IIS Web-Garden–which is configured to allocate up to four processes. In our Web Application the first user that hits the site causes the loading of all of the cached items. Since we are running in a IIS Web-Garden it ultimately takes up to four first time users to build up the cache for each of the four Web-Garden processes. This cache building takes 30-40 seconds, we've tried to make it faster, but it's unlikely that that can be improved any more.

This is unacceptable, we have been tasked with making the site fast for everyone all the time (no waiting for cache initialization). I would like to employ a solution that crawls the site to pre-heat the cache. The problem is that the Web-Garden feature appears to be a black box–you have no way of controlling if/when IIS will decide to load that 2nd, 3rd or 4th process when hit with the next HTTP request.

To me this seems like a common problem, but searching for a solution has yielded little results. My question is, is there a way through HTTP headers or some other construct to give IIS a hint, that you would like it to load or at least route to process 2,3,4 etc?

Best Answer

According to the Microsoft engineers this is not possible with IIS 6. However they have added a new feature in IIS 7.5 and ASP.Net 4.0 that has a nice provision for exactly what i'm looking for here. It's called the "preloadProvider". Here is an example snippet below (very cool!).

http://forums.iis.net/p/1158476/1907392.aspx

Because a single application pool can contain multiple applications, you specify individual applications to be automatically started by using the following configuration in theapplicationHost.config file:

<sites>

  <site name="MySite" id="1">

    <application path="/"

         preloadEnabled="true"

         preloadProvider="PrewarmMyCache" >

        <!--  Additional content -->

    </application>

  </site>

</sites>



<!-- Additional content -->



<preloadProviders>

     <add name="PrewarmMyCache"

         type="MyNamespace.CustomInitialization, MyLibrary" />

</preloadProviders>

When an IIS 7.5 server is cold-started or when an individual application pool is recycled, IIS 7.5 uses the information in the applicationHost.config file to determine which Web applications need to be automatically started. For each application that is marked for auto-start, IIS7.5 sends a request to ASP.NET 4.0 to start the application in a state during which the application temporarily does not accept HTTP requests. When it is in this state, ASP.NET instantiates the type defined by the preloadProvider attribute (as shown in the previous example) and calls into its public entry point. You create a managed auto-start type with the necessary entry point by implementing the IProcessHostPreloadClient interface, as shown in the following example:

public class CustomInitialization :  System.Web.Hosting.IProcessHostPreloadClient

{

    public void Preload(string[]  parameters)

    {

        // Perform initialization.

    }

}

After your initialization code runs in the Preload method and the method returns, the ASP.NET application is ready to process requests. With the addition of auto-start to IIS 7.5 and ASP.NET 4.0, you now have a well-defined approach for performing expensive application initialization prior to processing the first HTTP request. For example, you can use the new auto-start feature to initialize an application and then signal a load-balancer that the application was initialized and ready to accept HTTP traffic.

Related Topic