views:

553

answers:

2

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?

+1  A: 

Perhaps use a web monitoring tool to periodically access your web application. In addition to being able to send you an email / page you when your site goes down or otherwise doesn't behave as expected, such tools can have the beneficial side-effect of keeping your web app "hot" based on which pages and at what frequency the tool would be configured to access the site.

In theory, IIS would be allocating the incoming requests in a round-robin fashion across gardens, once they are all initialized. What might work best would be to configure the monitoring tool with a variety of URLs in your app that doesn't amount to a straight multiple of the number of processes in your garden -- otherwise the same gardens would always get hit with the same subset of URLs, assuming no other site activity. Anyway, if configured right, after a few rounds your gardens should all be hot.

Chris W. Rea
+1 good suggestion. We already have a Google appliance hitting the site all day long, but apparently IIS has some affinity mask where it always directs users of the same source to the same process. I need a way to guarantee that all 4 processes are heated up.
James
+1  A: 

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.

James