views:

190

answers:

4

Right now, my site is served by a single server, but I anticipate the need to increase my server capacity, soon. Instead of splitting my websites up among multiple servers and having to manage sessions across servers, I want to have multiple web servers all with the same code base on them and use router based round robin load sharing to distribute users to each server. And once a user hits a web server, have him stay with that web server throughout his/her whole session. To my knowledge, I don't need to have any special asp.net code to facilitate this.

Does anyone have any caveats or comments for this approach?

+1  A: 

What you are talking about is called sticky sessions or session affinity. If your router supports this, then you are golden.

The only caviat is that the load balancing won't be perfect. If you have a few high-load users who all end up randomly on the same server, they will staty there until the sessions end.

I have implemented this kind of load balancing where I work, and it requires no special asp.net code to implement.

Ryan Michela
+1  A: 

Most (perhap all) load balancers do have the ability to enforce "sticky" sessions where users on the same IP are directed to the same web server on every request. There is no code change required to accomplish this. There are two caveats that come to mind:

  1. Using sticky sessions will mean that the traffic load will not be distributed as evenly as it would if you were not using sticky sessions. However, the distributionshould be"even enough" IMO.
  2. There will be a very small percentage of users using proxy servers that may come in on different IPs on different requests. These users may experience "odd" behavior as they get passed to different servers.
Matt Wrock
+1  A: 

Another characteristic of this configuration is that if one your servers go down the sessions of the users on that server will lose their session as well. I think this is one of the most commonly used setup since it does not require any development effort if the router supports sticky session or session affinity.

Nikhil
+1  A: 

As others have mentioned, you should be able to turn on Sticky Sessions on your load balancer, that should take care of most of the "stay on one server" issues for you.

However you will want to ensure you have put settings in place to cope with a user landing on the wrong server mid session - Sticky Sessions are usually based on IP address, and users IPs can change mid session if you're unlucky, or a server may go offline, and the user will be directed to the other server.

You should make sure that your MachineKeys are the same across all servers - this will ensure that you can decrypt the viewstate correctly on all servers.

If you own the servers, you can do this in the machine.config, otherwise you can set it at the application level in the web.config, more details can be found in this how to:

Configure MachineKey in ASP.NET 2.0

There are some slight differences if you're running on IIS 7.5 - Tess Ferrandez has more details in a recent post "Forms authentication fails after installing IIS 7.5".

The other thing you'll probably want to do is move your sessionState from InProc to either Sql or StateServer.

Zhaph - Ben Duguid
@Zhaph - Ben Duguid: I am novice on this. You comment added some confusion. Your soultion is for Web farm scenario where all web server can take request in dependent of which one servered previous request. While @langekg is asking question about the single web server serving all the request based on ip address. But if he configure web farm based on your solution, he should be able to configure something where all server can server any request based on load. Please can you update more on my thought.
Neil
Hi Neil, The original question states: "I want to have multiple web servers all with the same code base on them and use router based round robin load sharing to distribute users to each server" - That sounds like a farm to me. Directing traffic to a server based on IP is a feature of the router. My answer is pointing out that without any changes to his code base, just some tweaks to configuration, he will be able to add resiliency into his setup so that if a server goes offline for any reason, the users on there don't lose their session as they are moved to the other server.
Zhaph - Ben Duguid