ASP.NET website scalability experience

Last six months have been great for me when I was exposed to the great world of scalability of my product. I will try to summarize some of my findings regarding scalability and then may take some of those stuff in detail in coming days/weeks/months.

  1. Before we start anything related to scalability for the website measure the performance of the pages with a single user on a idle bandwidth above 500 KB/s.
  2. To measure the response time of pages do the following
    1. Install tool like HTTPWatch on your machine. The basic version is free and available on
    2. Set the expiry content on the virtual directory to large number of days i.e. 3 or 5 or 10 (this can changed based on your particular need).
    3. Set the Application Pool(IIS 6.0) property such shutdown worker process if idle for 20 minutes and restart after 1740 minutes. (Switch off this setting).
    4. Now traverse through the selected interactions that you would like to measure once. This will warm up the browser cache.
    5. Now measure the response time using the HTTPWatch.
    6. If the response time of the page are below 3 seconds then it is right case for scalability otherwise first tune the pages to bring the response time below 3 seconds.
  3. One of the first thing that you should target to improve the scalability is to start with the database layer.
    1. Check how many queries are getting fired per interaction.
    2. Is there any redundant data being fetched.
    3. If yes then can we cache the data to lesser down database resource usage.
    4. Can we differentiate between Read and Write operations on database.
    5. If yes then can we have separate connection string for both of them.
    6. This is useful if you want to have separate database for Read and Write. (Synchronization can be an issue, will propose my proposal in later posts).
  4. Moving to the website having aspx pages,
    1. Are you using Session variables?
    2. If yes then use ASP.NET State Service for storing the session variables.
    3. Do you store the data in files?
    4. If yes then can they be stored on shared location.
    5. Do you generate content dynamic?
    6. If yes then can they move to shared location.
    7. Now use the VS 2005 Load Test tool to identify the bottleneck for number of users at which the website starts breaking or deteriorating.
  5. Use Windows 2003 Server Network Load Balancing (NLB) component to load balanced your website. Its simple to configure and leverage.
  6. Now again use the VS 2005 to load test tool to measure now at what point the website starts deteriorating.

One of the reason of slow response time is the way we have written the ASPX pages. In my coming post I will share my experience.

Setting ASP.NET State Service on Remote Machine

ASP.NET does allow to set the ASP.NET State Service on a separate machine. This is done through the appropriate setting on the web.config file.

But this is not the only change that we need to do we have set the registry settings on the machine where ASP.NET State Service is running.

We need to do change the the following key


and change the value of AllowRemoteConnection to 1 instead of 0.

Remove Cookie in ASP.NET

I was working on the Cookies using the HTTPCookie class in ASP.NET. Though it is simple to add cookie and use them in the program but I really struggle to remove the cookies. I tried initially

  1. Get the reference to the cookie.
  2. Use the Response.Cookies.Remove method to remove the cookie.

I expected the API to behave as per the name i.e. delete the cookie but to my utter shock it didn’t work. After long search I found the solution. The key was to make the cookie expire instead of removing it from the collection

Response.Cookies[“MY_COOKIE”].Expires = DateTime.Now;

This works perfectly for me.


ASP.NET Config files: Un-necessary Strings

We have been using ANTS Profiler lately to understand the memory behaviour of our ASP.NET application. What we observed is

  1. Too much memory have been allocated by Strings Objects.
  2. These string objects survives across many GC collection.

When we drill those strings more, we discovered

  1. That these are not our strings.
  2. Actually ASP.NET loads the settings of machine.config and web.config into the memory.
  3. I can now make out why it need to unload the AppDomain when we change these config files as the environment have to reload the settings again.
  4. There are many settings in these config files which have no relevance to our application.
  5. So we started commenting or removing from the machine.config file. (We took the backup of the ORIGINAL file).
  6. For e.g. webPart settings. We removed the entire block.
  7. We tested our web application and found everything to work fine.
  8. We then started removing those un-necessary entries.
  9. We then used the ANTS profiler to profile the memory and found that we save some 58 MB of memory by doing so.
  10. There was direct impact on the Gen 0 collection.

We haven’t decided whether we will do these on our production server but these can be done provided our application is the only app being used on that server.

Please take appropriate backup before trying this out.

All About Response.Redirect

Got some good resource on Response.Redirect. I have just tried to aggregate those through this post.

How Response.Redirect Works ?

Why Response.Redirect throwing exception in ASP.NET?

 Solution to avoid exception