Configuration Example

<Cluster className=”org.apache.catalina.ha.tcp.SimpleTcpCluster”

channelSendOptions=”6″>

 

<Manager className=”org.apache.catalina.ha.session.BackupManager”

expireSessionsOnShutdown=”false”

notifyListenersOnReplication=”true”

mapSendOptions=”6″/>

<!–

<Manager className=”org.apache.catalina.ha.session.DeltaManager”

expireSessionsOnShutdown=”false”

notifyListenersOnReplication=”true”/>

–>

<Channel className=”org.apache.catalina.tribes.group.GroupChannel”>

<Membership className=”org.apache.catalina.tribes.membership.McastService”

address=”228.0.0.4″

port=”45564″

frequency=”500″

dropTime=”3000″/>

<Receiver className=”org.apache.catalina.tribes.transport.nio.NioReceiver”

address=”auto”

port=”5000″

selectorTimeout=”100″

maxThreads=”6″/>

 

<Sender className=”org.apache.catalina.tribes.transport.ReplicationTransmitter”>

<Transport className=”org.apache.catalina.tribes.transport.nio.PooledParallelSender”/>

</Sender>

<Interceptor className=”org.apache.catalina.tribes.group.interceptors.TcpFailureDetector”/>

<Interceptor className=”org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor”/>

<Interceptor className=”org.apache.catalina.tribes.group.interceptors.ThroughputInterceptor”/>

</Channel>

<Valve className=”org.apache.catalina.ha.tcp.ReplicationValve”

filter=”.*\.gif|.*\.js|.*\.jpeg|.*\.jpg|.*\.png|.*\.htm|.*\.html|.*\.css|.*\.txt”/>

 

<Deployer className=”org.apache.catalina.ha.deploy.FarmWarDeployer”

tempDir=”/tmp/war-temp/”

deployDir=”/tmp/war-deploy/”

watchDir=”/tmp/war-listen/”

watchEnabled=”false”/>

 

<ClusterListener className=”org.apache.catalina.ha.session.ClusterSessionListener”/>

</Cluster>

Break it down!!

 

<Cluster className=”org.apache.catalina.ha.tcp.SimpleTcpCluster”

channelSendOptions=”6″>

The main element, inside this element all cluster details can be configured. The channelSendOptions is the flag that is attached to each message sent by the SimpleTcpCluster class or any objects that are invoking the SimpleTcpCluster.send method. The description of the send flags is available at our javadoc site TheDeltaManager sends information using the SimpleTcpCluster.send method, while the backup manager sends it itself directly through the channel.

For more info, Please visit the reference documentation

 

<Manager className=”org.apache.catalina.ha.session.BackupManager”

expireSessionsOnShutdown=”false”

notifyListenersOnReplication=”true”

mapSendOptions=”6″/>

<!–

<Manager className=”org.apache.catalina.ha.session.DeltaManager”

expireSessionsOnShutdown=”false”

notifyListenersOnReplication=”true”/>

–>

This is a template for the manager configuration that will be used if no manager is defined in the <Context> element. In Tomcat 5.x each webapp marked distributable had to use the same manager, this is no longer the case since Tomcat you can define a manager class for each webapp, so that you can mix managers in your cluster. Obviously the managers on one node’s application has to correspond with the same manager on the same application on the other node. If no manager has been specified for the webapp, and the webapp is marked <distributable/> Tomcat will take this manager configuration and create a manager instance cloning this configuration.

For more info, Please visit the reference documentation

 

<Channel className=”org.apache.catalina.tribes.group.GroupChannel”>

 

The channel element is Tribes, the group communication framework used inside Tomcat. This element encapsulates everything that has to do with communication and membership logic.

For more info, Please visit the reference documentation

 

<Membership className=”org.apache.catalina.tribes.membership.McastService”

address=”228.0.0.4″

port=”45564″

frequency=”500″

dropTime=”3000″/>

 

Membership is done using multicasting. Please note that Tribes also supports static memberships using theStaticMembershipInterceptor if you want to extend your membership to points beyond multicasting. The address attribute is the multicast address used and the port is the multicast port. These two together create the cluster separation. If you want a QA cluster and a production cluster, the easiest config is to have the QA cluster be on a separate multicast address/port combination than the production cluster.

The membership component broadcasts TCP address/port of itself to the other nodes so that communication between nodes can be done over TCP. Please note that the address being broadcasted is the one of theReceiver.address attribute.

For more info, Please visit the reference documentation

 

<Receiver className=”org.apache.catalina.tribes.transport.nio.NioReceiver”

address=”auto”

port=”5000″

selectorTimeout=”100″

maxThreads=”6″/>

 

In tribes the logic of sending and receiving data has been broken into two functional components. The Receiver, as the name suggests is responsible for receiving messages. Since the Tribes stack is thread less, (a popular improvement now adopted by other frameworks as well), there is a thread pool in this component that 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.

For more info, Please visit the reference documentation

 

<Sender className=”org.apache.catalina.tribes.transport.ReplicationTransmitter”>

<Transport className=”org.apache.catalina.tribes.transport.nio.PooledParallelSender”/>

</Sender>

 

The sender component, as the name indicates is responsible for sending messages to other nodes. The sender has a shell component, the ReplicationTransmitter but the real stuff done is done in the sub component,Transport. Tribes support having a pool of senders, so that messages can be sent in parallel and if using the NIO sender, you can send messages concurrently as well.

Concurrently means one message to multiple senders at the same time and Parallel means multiple messages to multiple senders at the same time.

For more info, Please visit the reference documentation

 

<Interceptor className=”org.apache.catalina.tribes.group.interceptors.TcpFailureDetector”/>

<Interceptor className=”org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor”/>

<Interceptor className=”org.apache.catalina.tribes.group.interceptors.ThroughputInterceptor”/>

</Channel>

 

Tribes uses a stack to send messages through. Each element in the stack is called an interceptor, and works much like the valves do in the Tomcat servlet container. Using interceptors, logic can be broken into more manageable pieces of code. The interceptors configured above are:

TcpFailureDetector – verifies crashed members through TCP, if multicast packets get dropped, this interceptor protects against false positives, ie the node marked as crashed even though it still is alive and running.

MessageDispatch15Interceptor – dispatches messages to a thread (thread pool) to send message asynchrously.

ThroughputInterceptor – prints out simple stats on message traffic.

Please note that the order of interceptors is important. the way they are defined in server.xml is the way they are represented in the channel stack. Think of it as a linked list, with the head being the first most interceptor and the tail the last.

For more info, Please visit the reference documentation

 

<Valve className=”org.apache.catalina.ha.tcp.ReplicationValve”

filter=”.*\.gif|.*\.js|.*\.jpeg|.*\.jpg|.*\.png|.*\.htm|.*\.html|.*\.css|.*\.txt”/>

 

The cluster uses valves to track requests to web applications, we’ve mentioned the ReplicationValve and the JvmRouteBinderValve above. The <Cluster> element itself is not part of the pipeline in Tomcat, instead the cluster adds the valve to its parent container. If the <Cluster> elements is configured in the <Engine> element, the valves get added to the engine and so on.

For more info, Please visit the reference documentation

 

<Deployer className=”org.apache.catalina.ha.deploy.FarmWarDeployer”

tempDir=”/tmp/war-temp/”

deployDir=”/tmp/war-deploy/”

watchDir=”/tmp/war-listen/”

watchEnabled=”false”/>

 

The default tomcat cluster supports farmed deployment, ie, the cluster can deploy and undeploy applications on the other nodes. The state of this component is currently in flux but will be addressed soon. There was a change in the deployment algorithm between Tomcat 5.0 and 5.5 and at that point, the logic of this component changed to where the deploy dir has to match the webapps directory.

For more info, Please visit the reference documentation

 

<ClusterListener className=”org.apache.catalina.ha.session.ClusterSessionListener”/>

</Cluster>

 

Since the SimpleTcpCluster itself is a sender and receiver of the Channel object, components can register themselves as listeners to the SimpleTcpCluster. The listener above ClusterSessionListener listens for DeltaManager replication messages and applies the deltas to the manager that in turn applies it to the session.

For more info, Please visit the reference documentation

Bind session after crash to failover node
Cluster Architecture

Get industry recognized certification – Contact us

keyboard_arrow_up