Thursday, 1 May 2014

Web Farm and Web Garden

Visual Studio has its own integrated ASP.NET engine which is used to run the ASP.NET Web application from Visual Studio. ASP.NET Development Server is responsible for executing all the requests and responses from the client. Now after the end of development, when you want to host the site on some server to allow other people to access, concept of web servers comes in between.
A web server is responsible for providing the response for all the requests that are coming from clients. The below diagram shows the typical deployment structure of an ASP.NET Web application with a single IIS.
Clients request for resources and IIS process the request and send back to clients.

Web Farm:
This is the case where you have only one web server and multiple clients requesting for resources from the same server. But when are huge amount of incoming traffic for your web sites, one standalone server is not sufficient to process the request. You may need to use multiple servers to host the application and divide the traffic among them. This is called “Web Farm”. So when you are hosting your single web site on multiple web servers over load balancer is called “Web Farm”. The below diagram shows the overall representation of Web Farms.

In general web farm architecture, a single application is hosted on multiple IIS Server and those are connected with the VIP (Virtual IP) with Load Balancer. Load Balancer IPs are exposed to external world to access. So whenever some request will come to server from clients, it will first hit the Load Balancer, then based on the traffic on each server, LB distributes the request to the corresponding web server. These web servers may share the same DB server or maybe they can use a replicated server in the back end.
So, in a single statement, when we host a web application over multiple web servers to distribute the load among them, it is called Web Farm.

Web Garden:
When we are talking about requesting processing within IIS, Worker Process(w3wp.exe) takes care of all of these. Worker Process runs the ASP.NET application in IIS. All the ASP.NET functionality inside IIS runs under the scope of worker process. Worker Process is responsible for handling all kinds of request, response, session data, cache data. Application Pool is the container of worker process. Application pool is used to separate sets of IIS worker processes and enables a better security, reliability, and availability for any web application.

Now, by default, each and every Application pool contains a single worker process. Application which contains the multiple worker process is called “Web Garden”. Below is the typical diagram for a web garden application.
In the above diagram, you can see one of the applications containing the multiple worker processes, which is now a web garden.
So, a Web application hosted on multiple servers and access based on the load on servers is called Web Farms and when a single application pool contains multiple Worker processes, it is called a web garden.

Create Web Garden in IIS 6 and IIS 7
How you can change the Number of Worker processes in both IIS 6 and IIS 7. For IIS 6, Right Click on Application Pool > Properties > Goto Performance Tab.
In the “Performance Tab” section, you would have one option called “Web Garden” where worker process sets to “1”, you can set the number of worker processes that you required.
For IIS 7, Right Click on Application Pool > Go To Advance Settings > In Process Model section, you will have “Maximum Worker Processes”. You can change it more than 1 to make it as a web garden.
In the above image, you can also check the definition of Web Garden.

Advantages of Web Farm and Web Garden
Advantages of Web Farm
1)    It provides high availability. If any of the servers in the farm goes down, Load balancer can redirect the requests to other servers.
2)    Provides high performance response for client requests.
3)    Provides better scalability of the web application and reduces the failure of the application.
4)    Session and other resources can be stored in a centralized location to access by all the servers.
Advantages of Web Garden
1)    Provides better application availability by sharing requests between multiple worker processes.
2)    Web garden uses processor affinity where application can be swapped out based on preference and tag setting.
3)    Less consumption of physical space for web garden configuration.

How to Manage Session in Web Farm Mode?
While using session, requests are distributed among different servers. By default, session mode is set to In Proc where session data is stored inside worker process memory. But, in Web farm mode, we can share the session among all the servers using a single session store location by making it Out proc (State Server or SQL Server Mode). So, if some of the servers go down and request is transferred to the other server by the Load balancer, session data should be available for that request.
In the above diagram, you can see that we can both the IIS server sharing the same session data which is stored in out of worker process.

How to Manage Session in Web Garden Mode?
When we are using Web garden where request is being taken care of by different worker process, we have to make the session mode as out process session mode. For Web Garden, we have to configure the out process within the same server but for different worker process.
While using Web garden with your application, you need make a couple of configuration settings in web.config in <process Model> section where you need to set certain properties like cpuMaskRequestLimitwebGardenClientConnectCheck, etc.

When we host a web application over multiple web servers to distribute the load among them, it is called Web Farm and when one application has multiple worker processes, it is called a Web garden.

No comments:

Post a Comment