Why use a cluster? There are two main reasons: first, for some core systems require long-term non-disruptive services, in order to provide high availability we need a cluster of multiple machines, on the other hand, as the traffic becomes more and more complex business logic, single machine processing capacity is not enough to deal with so many and complex logic, A number of additional machines are required to improve the overall service processing capacity.
If a Web application does not involve a session, then the cluster is quite simple, because the nodes are stateless, the nodes in the cluster do not need to communicate with each other, only need to evenly distribute the individual requests to the cluster node. But basic all Web applications will use the session mechanism, so The whole difficulty in Web application clustering is the synchronization of session data, of course, you can avoid complex data synchronization by some strategies, For example, as mentioned earlier, storing session information in a distributed cache or in a database is centrally managed, as each Tomcat instance simply writes or reads the database, avoiding communication between the Tomcat clusters. However, there are shortcomings in this approach, as well as the additional introduction of database or caching services, while ensuring their high availability and increased machine and maintenance costs.
In view of the shortcomings above, providing another solution is that the Tomcat cluster nodes themselves complete their own data synchronization, regardless of the access to which node can find the corresponding session, such as the first time the client access to the build session,Tomcat It synchronizes the session information to the other nodes, and it synchronizes the request during each request completion . Session all operations, so that the next request to any node in the cluster can find the response session information, and can guarantee the timeliness of information. It is easy to see that the session between nodes of the cluster is 22 of each other, once the number of cluster nodes and access to large, will lead to a large number of session information need to replicate with each other, it is easy to cause network congestion, and these synchronization operations are likely to become the bottleneck of overall performance, based on experience, The number of cluster nodes recommended in the actual production of this scheme is 3-6 , unable to build a larger cluster, and redundant large amount of data, utilization is not high.
The network traffic of full-node replication increases with the increase in the number of nodes, it is because of this factor that can not build a larger cluster, in order to make the cluster node can increase, the primary solution is the data replication traffic growth problem, the next section will introduce another kind of session management, each session will only have one backup, It causes the network traffic of the session backup to increase linearly with the number of nodes, greatly reduces the network traffic and logical operation, can build a larger cluster.
Students who like Java can add a friend:
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Cluster mode of management from single machine to cluster session