How do I save state across multiple web servers?

Is it possible to connect multiple web servers to a SQL Server cluster and maintain a user session?

I've been thinking about various approaches. The one that Microsoft's site suggests should use response.redirect for the "correct" server. While I can understand the reasoning behind this, it seems short-sighted.

If the load balancer is sending you to the server that is currently under the least stress, surely as a developer you should comply with this?

Are there any best practices in this case? If so, I would appreciate knowing what they are and any details on the pros and cons of using them.

+2


source to share


4 answers


Some parameters:

The load balancer can be configured to have sticky sessions. Make sure the application session timeout is less than load balancers, or you will get bounced with unpredictable results.

You can use a designated government server to handle the session. Then it doesn't matter where they bounce off the LB.



You can use SQL Server to manage your session.

Check it out on the server. https://serverfault.com/questions/19717/load-balanced-iis-servers-with-asp-net-inproc-session

+2


source


I am taking here from my experience with Java App Servers, some of which have very complex balancing algorithms.

A reasonable general assumption is that "Session Affinity" is preferred to balance each request. If we allocate an initial request for each user with some level of knowledge about the workload (or even on a random basis) and the population comes and goes, we get sane behavior. Remember, the goal is to give every user a good experience so you don't end up with evenly used servers!



In the event of a server crash, we can see our requests move eleswhere, and we expect our session to be migrated. The whole way to do this (session in DB, session state associated with high speed messaging ...).

+2


source


While you can use sticky sessions in your load balancer, it is better to use your session with State Server instead of InProc. At this point, all of your web servers can point to the same state server and exchange sessions.

http://msdn.microsoft.com/en-us/library/ms972429.aspx MSDN has a lot to say on the topic: D

UPDATE:

State Server is a service on your windows servers windows, but yes, it creates a single point of failure.

In addition, you can specify to serialize the session to SQL Server, which would not be the only point of failure if you were to handle it.

I'm not sure how "heavy" the workload for a government server is, does anyone else have any metrics?

0


source


This is not the answer you are looking for, but can you eliminate the NEED for the session state? We went to great lengths to encode whatever might be required between requests on the page itself. So I have nothing to do with farm-wide state or scalability issues, having to hang on to something owned by someone who can never go back.

0


source







All Articles