Feb 11, 2010

Web Farm (Load Balancing)

Web farm term is used for load balancing. It means running a web application (or a website) on multiple servers to distribute workload. If there are too much traffic on a server then distributing load among servers is a good way. It is scalable. Once you created an environment you can add more servers easily. But there are some criteria that must be taken into consideration:
First make it clear whether there is high traffic load on your server or not. Using cache or any other technologies may solve problem. Don't jump into load balancing solution until defining real problem. Problems may come from database. The database server may have wrong configuration or insufficient hardware. Network configuration also have a place in problem space.
If you decide to make web farm then you should use a load balancer. There are very smart balancers that have features like firewall, cache, filtering, client authentication, tcp buffering, http compression, DDoS protection and so on. 
Be careful when you update your website. To keep all servers synchronized all of them must be updated. Deploying new versions must be tracked.
As you see there are too much servers. We had one before load balance. After that we have at least 3- load balancer, 2 web servers.

I want to mention an important point about web farm in terms of Asp.net. A couple of years ago a company that have a load balancing solution came to us. We decided to try it. I don't know what they did on our servers. But i know they weren't successful. Because they didn't know how to manage ASP.NET sessions. This is another task that we need to complete. 

A state server must be created to keep sessions. I won't write detailed steps. You should know about tags that is used to set some parameters in web.config file. You may want to keep sessions on Sql Server than you must set sessionstate mode to SQLServer. You can read ASP.NET State Management Overview article.

<sessionstate cookieless="false" mode="SQLServer" sqlconnectionstring="data source=SERVERNAME; user id=sa; password=sa" stateconnectionstring="tcpip=" timeout="20">