Sogou Analysis of Tomcat cluster mechanism and its production deployment model

label TomcatcolonyClustermechanismSession synchronization
73 people read comment(0) Collection report

Why do you want to use clusters?

Why do you want to use clusters? There are two reasons: one is for some of the core system requirements can not be long-term interrupt service, in order to provide high availability we need to cluster consisting of multiple machines; on the other hand, with the access more and more and the logic of the business is getting more and more complex, single machine ability is not enough to handle so many and complex logic, so need to increase the number of machines so that the entire service processing capacity has been improved.

Where is the difficulty of cluster?

If one saysWebApplications not involving the session, then do cluster is quite simple, because nodes are stateless, the cluster nodes without need to communicate with each other, only need to each request distribution to cluster nodes can be. But basically allWebApplication will use the session mechanism, so doWebWhen applying the cluster, the difficulty lies in the synchronization of session data.

Of course, you can avoid the complexity of the amount of data synchronization operation, such as the front of the session information is stored in the distributed cache or database centralized management, the following diagram, eachTomcatExamples only need to write or read the database can be avoidedTomcatCommunication between clusters. But this approach also has the problem, to introduce additional database or cache services, but also to ensure that their high availability, increase the cost of the machine and maintenance.


Full node session synchronization model


In view of the shortcomings of the unification of storing the session to the database or cache, an alternative solution is provided.TomcatCluster nodes themselves to complete their data synchronization, regardless of access to which nodes are able to find the corresponding session, the following chart, the client's first access to generate a conversation,TomcatIn itself, the session information is synchronized to the other nodes, and it is the right time for each request to complete the request process in Chengdu.SessionIn this way, the next request to any node in the cluster can find the response of the session information, and can ensure the timeliness of the information. And out does not affect the overall foreign service every node dang.


Single node model

TomcatProvide the second cluster session management mechanism is the single node backup mechanism, here's a look at the specific ways of working mechanism, the cluster is usually through load balancing foreign provides overall service, all nodes hidden form a whole in the back-end. In front of a variety of modes to achieve the realization of the need to balance the load, so the load balancing is omitted. The most common way to load is in front ofApacheDrag all nodes, it supports will be similar"326257DA6DB76F8D2E38F2C4540D1DEA.tomcat1"Conversation"IDTo decompose and locate toTomcatCluster in order toTomcat1Name on the node.Stick SessionBy,JK ApacheModule implementation). Each session has an original and a backup, and the backup and the original will not be saved on the same node, as shown in the following figure.Tomcat1Instance node to generate a.tomcat1The suffix of the session ID, andTomcat1The node selects the node that is backed up by a certain policy, and then contains the{conversationIDBackupIp}Information sent toTomcat2,Tomcat3,Tomcat4, as shown in the dotted line in the graph, so that each node has a session.IDBackupIPA list, that is, each node has a backup of each session.IPAddress.

After the completion of the above step is to back up the session content to the backup node, ifTomcat1TheS1,S2The backup address for the two session isTomcat2, then the session object is backed up toTomcat2In the middle, similar to theTomcat2holdS3Session backup toTomcat4,Tomcat4holdS4,S5Two dialog backup toTomcat3In this way, all the sessions in the cluster have been backed up by a backup. WhenTomcat1Has not been a failure, becauseStick SessionTechnology clients will have access toTomcat1Node, to ensure that it has been able to get to the session. And whenTomcat1Out of the trouble, then.TomcatAlso provides aFailoverMechanism,ApacheSensing backend clustersTomcat1When the node is removed, it will randomly allocate the request to any other node, and then there will be two cases:

It just points to the backup nodeTomcat2At this time can still get toS1Conversation, in addition to this,Tomcat2And the other thing to do is to do this.S1Session label for the original and continue to select a backup address backupS1Session, so that there is a backup.

If you are divided into a non backup nodeTomcat3, this time certainly can not findS1Conversation, so it will be to the cluster all nodes to ask questions, "who do I have to askS1Session backupIPAddress information?" Because onlyTomcat2yesS1The backup address information, which receives the reply to the query to informTomcat3nodeS1Session backupTomcat2, according to this information will be able to findS1Session, andTomcat3In their own local generationS1Conversation and marked the original,Tomcat2A copy of the same, so that the same can be foundS1Session, normal complete the entire request processing.



Production deployment model

The above two models have their own advantages and disadvantages, in the actual production of the deployment should be based on the actual situation to choose the appropriate model.

For the full node session synchronization model

Conversation between scrutiny is easy to find in the cluster nodes are pairwise copy each other, once the cluster nodes and the number of visits, will lead to a large number of session information to each other synchronous replication, can easily lead to network congestion, and the synchronous operation probably will become the bottleneck of the overall performance, according to the experience, this scheme is recommended in practical production cluster number of nodes is3-6It can not form a larger cluster, and a lot of data redundancy, the utilization rate is low.

For clustered incremental session manager, the configuration can beServer.xmlFile to use it, inTomcatCluster mode is used in<Engine>Add nodes<cluster>Node, and the cluster increment session manager is the one that adds a child node to the node.<Manager className= "org.apache.catalina.ha.session.DeltaManager" / >.


Session Backup Model

For all of the top node session synchronization model for network traffic with the number of nodes increase was the square trend growth problems, it is also because the factors lead to the construction of large scale clusters, in order to make the cluster nodes can increase, the first to solve the is data replication traffic growth,TomcatProposed model for session backups on the front of the model were optimized. It makes backup session network traffic increases linearly increasing with the number of nodes, each session will only have a backup, which greatly reduces the network traffic and logic operation, this model can build larger clusters. Production can be composed of more than ten nodes as a cluster.

The cluster backup session manager can be configuredServer.xmlFile using it, its configuration andDeltaManagerThe configuration is basically similar in<cluster>Add a child node under the node<Manager className= "org.apache.catalina.ha.session.BackupManager" / >.

Using this model should also be taken into consideration, although this pattern supports the larger cluster, but it is only a data backup, if just for the source and backup data where the machine also dawdle out, cannot recover the data, but just at the same time the probability of outage very small very small.

Java students like to make friends:

step on
Guess you're looking for
View comments
* the above user comments only represent their personal views, does not represent the views or position of the CSDN website

    Name: seaboat sea boat


    personal data
    • visit119010 times
    • Integral:Two thousand seven hundred and thirteen
    • Grade
    • Rank:7829th name
    • original118
    • Reproduced:5
    • Translation:1
    • Comments:52
    Blog column
    Latest comments