Session Management for a Load Balanced Website

We are currently using a database to store state information (in a separate table) for the user. We retrieve this information from the database every time the user accesses the application (sends a request) and updates it in the database after the request has been processed.

This works very well for us in many of our projects and is very easy to implement, but it adds overhead for calling the database and saving the state information.

Are there other ways that might work better in this case?

+1


source to share


2 answers


Out of the box, MS offers StateServer mode . This allows session data to be kept in memory on a single server shared by one or more web servers. In some cases (if the state of the SQL Server session is under significant stress), it can give you a boost.

By default, the SQL Server Session Provider retrieves and stores session items for each item. If you know your usage of the session and it seems inefficient (you select and store multiple items for each request), you can implement a custom SessionState Store Provider in SQL Server that fetches all session items at the beginning of the query and stores them all at the end of the query.



Other resources:

+2


source


There are several strategies. I hope your session is sticky (i.e. Routed to the same machine all the time it gets up). In this case, you can cache the data locally (in memory) and use the database for backup only ("write-only"). In addition, there are solutions like memcached that provide a distributed cache.



0


source







All Articles