Web server cluster Session synchronization

Source: Internet
Author: User

After doing the Web cluster, you will certainly first consider the session synchronization problem, because through the load balancer, the same IP access to the same page will be assigned to different servers, if the session is not synchronized, a login user, one will be logged in, one will not be logged in state. So this article gives three different ways to solve this problem based on this situation:
first, the use of database synchronization session
I did not use this method in the long server session synchronization, if I have to use this method, I think of two ways:
1, a low-end computer to build a database dedicated to the session of the Web server, or, the special database is built on the file server, the user access to the Web server, will go to this special database check the session, in order to achieve the purpose of session synchronization.
2, this method is to put the table and other database tables to hold the session together, if MySQL also made a cluster, each MySQL node must have this table, and this session table data table to synchronize in real time.
Note: Using the database to synchronize the session, will increase the burden of the database, the database is prone to bottlenecks, if the session is placed in the database, is undoubtedly worse. The two methods above, the 1th method is better, the table of the session independent, reducing the burden of the real database
second, using cookies to synchronize session
Session is the file of the situation stored on the server side, the cookie is the situation of the file of the client, how to achieve synchronization? The method is simple, that is, the user access page generated by the session into the cookie, is to use a cookie as a transit point. You visit Web Server A, generated a session to put it into a cookie, you access is assigned to Web Server B, this time, Web Server B First determine if the server has this session, if not, Look at the client's cookie there is no this session, if not, that the session really does not exist, if there is a cookie, the cookie inside the Sessoin synchronization to the Web Server B, so that the session synchronization can be achieved.
Note: This method is simple, convenient, and will not increase the burden of the database, but if the client has forbidden the cookie, then the session will not be synchronized, this will bring a loss to the site, the security of the cookie is not high, although it has been added, but still can be forged.
third, the use of Memcache synchronization session
Memcache can be distributed, and without this function, he cannot be used to do session synchronization. He can combine the memory of a Web server into a "memory pool", which can be put into the "memory pool" regardless of which server the Sessoin is generated, and can be used by others.
Advantages: In this way to synchronize the session, does not increase the burden of the database, and security than with a large increase in the cookie, the session into memory, than from the file read much faster.
Disadvantage: memcache memory into many kinds of storage blocks, there is a block size, this way also decided that the memcache can not fully utilize memory, will produce memory fragmentation, if the storage block is insufficient, but also generate memory overflow.
Iv. Summary
Three of the above methods are feasible
The first method, the one that most affects the speed of the system, is not recommended;
The second method, the effect is good, but the existence of the same security risks;
Third method, personally feel that the third method is the best, recommend everyone to use

Web server cluster Session synchronization

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.