Click here to Skip to main content
15,867,308 members
Articles / Web Development / IIS

How To Enhance ASP.NET Application Responsiveness and Scalability using Garbage Collection Notifications

Rate me:
Please Sign up or sign in to vote.
3.57/5 (3 votes)
25 May 2009CPOL3 min read 21.2K   11   4
This article expresses a simple idea of how to enhance web application performance using Garbage Collection notifications.

Introduction 

This article expresses a simple idea of how to enhance web application performance using Garbage Collection notifications. No implementation so far. If anyone will have enough time to implement the approach described below, I will be happy to receive results and feedback.

C#
public static int Main(string[] args){... //method for main ideas 

What is the main problem of all web applications written today using .NET Framework or Java? IMHO, this is Garbage Collection. In order to perform GC, background GC thread needs to suspend all managed threads. And this can take a while, especially on 64-bit platform, where managed heap size can be pretty large. This means longer response time for the application users. You can ask “But what can we do here?”. We can react in a proper way. In .NET Framework 3.5 SP1, there is a new interesting feature – Garbage Collection notifications. More information can be found on MSDN here.

How to react? Let’s consider a typical server scenario with load balancer:

Click to enlarge image

Here we can see several+ servers with load balancer in front. IIS 6 is used in this scenario as the most widely used web server, IMHO, for ASP.NET applications. As is displayed in the image, we can, for instance, subscribe for GC notifications during application startup in Global.asax. Now let’s consider possible solutions depending on the feature set of load balancer.

  1. Load balancer can accept notifications from the server nodes. In this case, our approach is rather easy. When GC is about to happen, we notify load balancer with message “Hey, I will be overloaded with GC” and after GC - with “Ok, ready to fire!”. 
  2. Time interval, which LB uses for server polling, is bigger, than possible time required for GC. In this case we can implement custom ISAPI filter which each time will be notified about GC. In case of ongoing GC, ISAPI filter can redirect requests back to load balancer, so load balancer can re-schedule its execution on a different server, or return some custom HTTP code which basically will mean the same for properly configured load balancer. The possible problem here is that due to IIS 6 process model, custom ISAPI filter and our ASP.NET application will be hosted in separate processes. This can be easily solved with inter-process communication, memory-mapped files, WinAPI which allows to run particular method/function in particular process, etc. You can ask, why ISAPI, but not HTTP module, for instance. The answer is that during GC, all managed threads are suspended, so we need an unmanaged one to succeed with our mission.
  3. Time interval, which LB is used for server polling, is pretty small. In this case, we can configure load balancer to poll custom ISAPI extension. Why not HTTP handler? The answer is the same as in the case of “ISAPI filter vs HTTP module”. Here we’ll also need to communicate between separate processes. Load Balancer will constantly poll our custom ISAPI filter to get known about GCs happening on server side.

Summary

I have described three basic possible approaches. Of course there can be much more sophisticated ones. If you’ll find a better one – please let me know.

History 

  • 25th May, 2009: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Technical Lead bwin Interactive Entertainment AG
Austria Austria
The views expressed in my articles are mine and do not necessarily reflect the views of my employer.

if(youWantToContactMe)
{
SendMessage(string.Format("{0}@{1}.com", "liptchinski_vit", "yahoo"));
}

More info in my LinkedIn profile:
http://www.linkedin.com/in/vitaliyliptchinsky

Comments and Discussions

 
General[My vote of 1] Do the implementation first, then write the article Pin
MR_SAM_PIPER1-Jun-09 15:33
MR_SAM_PIPER1-Jun-09 15:33 
Otherwise, it just looks like you are trying to get other people to do your work for you. In itself, this article provides no information on GC Notifications at all.
GeneralRe: [My vote of 1] Do the implementation first, then write the article Pin
Vitaliy Liptchinsky1-Jun-09 21:40
Vitaliy Liptchinsky1-Jun-09 21:40 
RantRe: [My vote of 1] Do the implementation first, then write the article Pin
MR_SAM_PIPER1-Jun-09 22:23
MR_SAM_PIPER1-Jun-09 22:23 
GeneralRe: [My vote of 1] Do the implementation first, then write the article Pin
Vitaliy Liptchinsky1-Jun-09 22:39
Vitaliy Liptchinsky1-Jun-09 22:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.