Tomcat Cluster in the Cloud
The platform multicast and redirecting requests to each server with load balancer provides session replication between the pairs of server nodes. This guarantees session exchange between the nodes through the local net and eliminates the need of additional software or Memcached. With this approach you can use a big clustered app hosting.
This instruction shows the clustering technology used in the platform by the example of the Tomcat app server.
The given scheme presents a Tomcat cluster with two servers and one load balancer. All requests are handled and distributed by the balancer between different nodes due to the availability and server load.
If one of the servers fails, the users from that node will be automatically switched to the other instance of this Tomcat cluster. Thanks to the replication, the other instance already has all the sessions of the failed node, so end-users never notice any change.
To use the Tomcat clustering in the platform, you have to perform the next steps:
1. Log into your platform dashboard.
2. Click New Environment.
3. Pick Tomcat as the application server you want to use, specify the cloudlet limits and turn on High-availability as shown in the picture below. State the name of the environment and click Create.
When you enable High Availability a special Tomcat config file (iNET.elastic-ha.xml) is generated for each node by our system. Here is an example:
|
|
Let’s look through this file in details:
1. This is the major element, inside which all the other cluster elements are configured.
|
|
The channelSendOptions flag is attached to every message sent by SimpleTcpCluster class or any objects that are calling the SimpleTcpCluster.send method.
2. The DeltaManager uses the SimpleTcpCluster.send method to send information though the channel.
|
|
3. The group communication framework inside Tomcat is called Tribes. It is used as the channel element here. It encapsulates everything that relates the membership, logic and communication.
|
|
4. Membership is made using multicast. Tomcat cluster separation consists of a multicast address and port number. Communication between nodes is realized over TCP.
|
|
{MagicPort} is a unique port number for the cluster, which is generated on the fly from the Java arguments.
5. Tribes' logic of sending and receiving data includes two components: sender and receiver. The Receiver is responsible for data receiving. There is a thread pool in this element which has a maxThreads and minThreads setting. The address attribute is the host address that will be broadcasted by the membership component to the other nodes.
|
|
6. The Sender component is responsible for sending messages to other nodes. The Sender includes the ReplicationTransmitter, a special shell component, and Transport sub component. Messages can be sent concurrently with the NIO sender and parallel with pool of senders.
|
|
7. The elements of the Tribes stack interceptors are:
- TcpFailureDetector - verifies crashed members via TCP
- MessageDispatch15Interceptor - dispatches messages to a thread pool to send message asynchronously
|
|
8. The cluster uses valves to track requests to web applications:
- ReplicationValve finds out when the request has been completed and initiates the replication
- JvmRouteBinderValve is responsible for backing up your data
|
|
9. The SimpleTcpCluster is a sender and receiver of the Channel object, so components are registered as listeners to this cluster.
|
|
High Availability configuration is automated so you can easily set it up for every Java app server supported by the platform.