Load Sharing for ASP.NET Sites

At the moment my site is served by one server, but I expect that soon I need to increase the bandwidth of my server. Instead of splitting my sites across multiple servers and managing sessions on different servers, I want to have multiple web servers on them with the same codebase and use router-based shared load balancing to distribute users to each server. And once the user hits the web server, ask him to stay with that web server for the entire session. As far as I know, I don't need any special asp.net code to facilitate this.

Does anyone have any caveats or comments on this approach?

+2


source to share


4 answers


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 load balancing won't be perfect. If you have multiple high load users who all accidentally end up on the same server, they will be static there until the session ends.



I have implemented load balancing like this where I work and does not require any special asp.net code to implement.

+1


source


Most (perhap all) load balancers have the ability to enforce sticky sessions where users on the same IP address are directed to the same web server on every request. This does not require any code change. There are two caveats that come to mind:



  • Using sticky sessions will mean that the traffic load won't be evenly distributed, as if you weren't using sticky sessions. However, allocation should be "enough" IMO.
  • There will be a very small percentage of users using proxy servers that can appear on different IP addresses for different requests. These users may experience "strange" behavior as they are sent to different servers.
+1


source


Another notable feature of this configuration is that if one of your servers goes down, user sessions on that server will also lose their session. I think this is one of the most commonly used settings as it doesn't require any development effort if the router supports session sticky or session proximity.

+1


source


As mentioned above, you should be able to enable Sticky Sessions on your load balancer, which should take care of most of the "stay on the same server" issues for you.

However, you will want to make sure that you set the settings to handle the user landing on the wrong server session. - Sticky Sessions are usually IP based, and users' IPs can change the average session if you are out of luck, or the server can go offline and the user will be redirected to another server.

You need to make sure your MachineKeys are the same on all servers - this will ensure that you can correctly decode the view state on all servers.

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

Configure MachineKey in ASP.NET 2.0

There are a few minor differences if you are running IIS 7.5. Tess Ferrandes has more details in the recent post " Forms Authentication Failed After Installing IIS 7.5 ".

Another thing you probably want to do is move sessionState from InProc to Sql or StateServer.

+1


source







All Articles