November 3, 2011

Web Garden - ASP.Net

When an application is hosted by multiple processes on the same server it is said to be a web garden environment.All IIS Requests process by worker process. By default each and every application pool contain single worker process. The worker process is a small Win32 shell of code that hosts the common language runtime (CLR) and runs managed code. It takes care of servicing requests for ASPX, ASMX, and ASHX resources. There is generally only one instance of this process on a given machine. All currently active ASP.NET applications run inside of it, each in a separate AppDomain.

Identical copies of the process run on all of the CPUs with affinity to the process, known as Web Garden.

Think of a web garden as a web farm, but all in the context of a single machine.

What are the Limitations?
You’d stuck with an application that assumes everything lives within the same worker process.

No InProc session state:
If you’re using session state in your application, then you need to use an out-of-process session state, such as the ASP.NET State Service or sessions stored in SQL Server. InProc session management won’t work because each worker process will be maintaining its own session state. If you use an out-of-process session state, then you can be sure that all worker processes are consulting the same single resource as the place to store and retrieve session data.

No built-in caching mechanism:
If you’re using in-proc Caching, you need to remember that each individual worker process is going to maintain its own cache. This can make an operation such as clearing the cache difficult.
A better solution would be to move to an out-of-process cache like memcached. Then you only have one service that you need to clear the cache for, and that cache clearing action will be observed by all worker processes.

Advantages:
  • Robust processing of requests. When a worker process in an application pool is tied up (for example, when a script engine stops responding), other worker processes can accept and process requests for the application pool.
  • There is also a reduced contention for resources. When a Web garden reaches a steady state, each new TCP/IP connection is assigned, according to a round robin scheme, to a worker process in the Web garden. This helps smooth out workloads and reduce contention for resources that are bound to a worker process.
  • Web gardening helps enable scalability on multiprocessor computers by distributing the work to several processes. This improves performance and eliminates cross processor lock contentions.
  • Application availability, Processes in a Web garden share the requests that arrive for that particular application pool. If one worker process fails, another worker process can continue to process requests.
  • Optimum utilization of processes running on multiple processors located in a single server
  • Binding the application to processor with the help of CPU masks (Processor affinity), applications can be swapped out and restarted on the fly.
  • Could be said as a provisional solution for faulty applications.
Disadvantages :
  • Many applications assume dedicated access to some system level resource.  when this kind of application starts, it takes exclusive access to a resource; so when a second version of the application starts, it fails to get this exclusive access.
  • Prevent the use of session state in the process. So in statefull application you have another performance penalty to serialize the state to an external store.
  • Low Performance for large volumes of data.

Scenerios Where could Use :
  • Application need to share resources and hence can cause contention of resources.
  • The application is not very CPU intensive.
  • There exists multiple instances of an application, each of which can be allocated a worker process.