Web Garden and Static Objects difficult to understand

1.4k Views Asked by At

I am in the process of investigating to convert our web application to the web farm. So I started with web garden, by converting the 'Maximum Worker Process = 3'. Following is the simplified version of my problem.

Following is my Static Object class.

public static class MyStaticObject
{
public static string MyProperty {get;set;}
}     

Then on Page Load I initialized the Static Objects as follows -

MyStaticObject.MyProperty = "My Static Property";

Then using asp.net ajax [WebMethod] create the ajax method on my web page

[WebMethod()]
public static string getStaticProperty()
{
  return MyStaticObject.MyProperty;
}

// Then I call this Ajax method using Javascript and set the return to the text box.

This test is not working as expected. Following are my assumptions and wrong outcome from the test.

  1. I thought when we set virtual directory to be web garden, then each request to the virtual directory is handled by different process in web garden, so my next few request to the server, should return null as I have initialized the static objects for one working process. But even if I click the ajax button for 20 times in row (means 20 requests) even then the static objects return me value.

  2. Am i right in assuming on restarting the IIS should kill all the static objects.

  3. Static objects are not shared in web gardens/web farms.

I am surprised by the behaviour of IIS, static objects and web garden.

Is I am assuming wrong or my way of testing is wrong.

Thanks.

1

There are 1 best solutions below

1
On BEST ANSWER

Your assumptions about the way static objects are managed in AppPools / web gardens is correct.

However, your assumption about the way that web requests are distributed is not. HTTP requests are round-robined by the http.sys driver to IIS worker processes only when a new TCP connection is established, not when a new request arrives. Since keepalives are enabled by default, even though you made 20 requests in a row, they probably were all served by the same IIS worker process.

You can have IIS disable keepalives for testing purposes from the HTTP Response Headers section in IIS Manager, under Set Common Headers. That should cause your browser to open a new connection for each request.

To test with keepalives enabled, you can use the Web Capacity Analysis Tool (WCAT), available with the IIS 6 Resource Kit, to generate a multi-threaded load that accesses both IIS processes in your web garden.