Pre-loading Web Applications in ASP.Net 4



In this article, we will get familiar with the new performance enhancement feature in ASP.Net 4 for preloading web applications.

Introduction

There are situations where Web applications can need large amounts of data to be loaded or require intensive initialization before the application can be operational.  If no action is taken, this would result in a delay in the first request that an application receives. As a work-around, in earlier versions, developers would implement a mechanism to 'touch' the application or 'wake' up the application and process the initialization activities in the Application Load event in global.asax. This would enable the application entry requirements to be filled in, after an IIS restart or an application pool start-up occurs.

ASP.Net 4 introduces a new built-in feature to provide this auto-start capability in the platform. This feature is available in the combination of ASP.Net 4, IIS 7.5 and Windows Server 2008 R2.

Mechanics


Here is the sequence flow for utilizing this new feature.

  1. The IIS Administrator sets an application pool to be automatically started by creating an application pool with the startMode set to "AlwaysRunning".  
  2. Specify individual applications that will be auto-started
    1. Set serviceAutoStartEnabled to true for the Web application
    2. Specify the serviceAutoStartProvider 
  3. The serviceAutoStartProvider is configured within the serviceAutoStartProviders section and can be set to a type which implements the IProcessHostPreLoadClient interface. 
  4. When IIS restarts or the application pool is recycled, the serviceAutoStartProvider is instantiated and it's Process method is executed. 
  5. Until the Process method is completed, the application is in a state in which it does not accept any HTTP requests. 
  6. Once the preloading is completed and the Process method returns, the application is ready to process new requests. 
Benefits
  • Standard mechanism to Prepare the Web application before servicing clients – ensure operation readiness
  • Integrate with Load balancers to include a server within a web farm after it is ready to process requests
  • Re-usability - this mechanism provides a way to define common preloading requirements for a third party platform or a product line in the AutoStartServiceProvider. 
Note

Per a Late breaking update - IIS Application Warm-Up Module for IIS 7.5:
Instead of writing custom code, you specify the URLs of resources to execute before the Web application accepts requests. During recycle, the old IIS worker process continues to execute requests until the newly spawned worker process is fully warmed up, so that applications experience no interruptions or other issues due to unprimed caches

References: MSDN, ASP.net

Conclusion

In this article, we took a look at the auto-start feature implementation in ASP.Net 4. I hope this encourages you to look into the details of using this solution in the future and consider areas where it may match your requirements.

Happy Coding!

Disclaimer
This article is for purely educational purposes and is a compilation of notes, material and my understanding on this subject. Any resemblance to other material is an un-intentional coincidence and should not be misconstrued as malicious, slanderous, or any anything else hereof. 

erver'>

Similar Articles