Because the Load Balancer server may distribute requests to any server on the cluster, it is more complex to ensure that each request gets the correct session than a single computer.
The main methods of session management under cluster environment
1.session replication
Session replication is an early enterprise-level use of a more server cluster session management mechanism. The application server opens the session copy function of the Web container, synchronizes the session object between several servers in the cluster, so that all session information is saved on each server, so that any downtime will not cause the session data loss. When the server uses the session, it is obtained directly from the local.
This way when the application cluster reaches thousands of, there will be bottlenecks, each need to backup session, there is insufficient memory.
2.session Bindings
The hash algorithm, such as Nginx Ip_hash, makes the same IP request distributed to the same server.
This approach does not meet the high availability requirements for the system, because once a server is down, the session on the machine is no longer there, the user requests to switch to another machine after the session, unable to complete the business processing.
3. Use cookies to record session
Session record in the client, each time the server request, the session is placed in the request sent to the server, the server after processing the request and then the modified session response to the client. The client here is a cookie.
Cookies are used to record the disadvantages of a session's page tour, such as limited by the size of the cookie, the information that can be recorded, and each request for a response requires a cookie to be passed, affecting performance, and if the user closes the cookie, access is not normal. But because
Cookies are easy to use, high availability, support the linear scaling of the application server, and most of the session confidence is relatively small, so in fact, many websites are more or less using cookies to record the session.
4.session Server
Session server can solve all the above problems, the use of independent deployment of the session server (cluster) Unified management session, use the server every time read and write session, all access to the session server.
This solution is in fact the application server state separation, divided into a stateless application server and stateful session server, and then for the different characteristics of the two servers to design the architecture respectively.
For stateful session servers, a relatively simple method is to utilize distributed cache (memcached), database, etc. The packaging is based on these products to meet the storage and access requirements of the session.
If the business scenario has higher requirements for session management, such as the use of Session service grassroots single Sign-On (SSO), user servers and other functions, the need to develop a dedicated session service management platform.
"From large Web site Technical architecture Book" Session Management for Application server clusters