Skip to main content

Tomcat Clustering : Session Replication with Backup Manager

Prerequisite Blogs:

How To Install Apache Tomcat

Multiple Tomcat Instances on Single Machine

Tomcat Clustering: Loadbalancing with mod_jk and Apache

Tomcat Clustering : Session Affinity

  

Backup Manager

Backup manager usually used clustered environment. Its like delta manger. But it will  replicate to exactly one other instance(backup instance). Its act  like one instance is Primary  and another instance as backup.

Steps to make Session Replication in Tomcat Clustering

I am continue from exactly where I left in last session affinity post. So check that post and make sure jumRoute all are set properly. Steps are
  1. Enable Multicast routing
  2. Add <Cluster> Entries in conf/server.xml file for all instances.
  3. Enable the Web Application as distributable

Step1:  Enable Multicast routing


In Linux Environment most of the system kernel is capable to process the multicast address. We need to add route entry in kernel routing table.

sudo route add -net 224.0.0.0 netmask 240.0.0.0 dev eth0

Here eth0 is Ethernet interface. Change according to your  interface.
In multicast address is belong to Class D address Range (224.0.0.0 to 239.255.255.255). So, we inform to kernel if any one access these address then it goes through eth0 interface.


Step2: Add <Cluster> Entries in conf/server.xml file for all instances.


This very important part for tomcat clustering. We need to Add <Cluster> tag in conf/server.xml file in all tomcat instances.

<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>

We can add this <Cluster> tag in either inside the<Engine> tag or <Host> tag.
Here SimpleTcpCluster is tomcat cluster implementation. This tag is looks like simple but its has many inner tags. If we omitted then its takes the default values. If we want do any customization (like change multicast address, receiving address port) we need to use complete <Cluster> tag.
This is complete <Cluster> tag:

<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"
                        channelSendOptions="8">
<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"/>
  <Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
  <Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/>
</Sender>
<Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
address="auto"
port="4000"
autoBind="100"
selectorTimeout="5000"
maxThreads="6"/>
<Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>
<Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/>
</Channel>

<Valve className="org.apache.catalina.ha.tcp.ReplicationValve" filter=""/>

<Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve"/>
 
 <ClusterListener className="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener"/> <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>

</Cluster>

 

Step3: Enable the Web Application as distributable


We need to make the our web application distributable. Its simple add <distributable/> tag in apps web.xml file. In according to servlet specification  <distributable/> tag in web.xml mention that any container to consider this application can work in distributed environment.

Note:
All session object in our web application must me serializable.

 

 

 

 

Comments

Popular posts from this blog

JavaMelody: Monitoring the Performance of Tomcat Application Server

Javamelody is an opensource (LGPL) application to monitor Java or Java EE application servers in QA and production environments. JavaMelody is mainly based on statistics of requests and on evolution charts. (Extract from the Javamelody home page) It allows to improve applications in QA and production Give facts about the average response times and number of executions Make decisions when trends are bad, before problems become too serious Optimize based on the more limiting response times Find the root causes of response times Verify the real improvement after optimization It includes summary charts showing the evolution over time of the following indicators: Number of executions, mean execution times and percentage of errors of http requests, sql requests, jsp pages or methods of business façades (if EJB3, Spring or Guice) Java memory Java CPU Number of user sessions Number of jdbc connections These charts can be viewed on the current day, week, month, year or cu...

How to install Oracle JDK on Ubuntu from repository

This package provides Oracle Java JDK 7 (which includes Java JDK, JRE and the Java browser plugin). However, you can't only install Oracle JRE - the PPA only provides the full Oracle JDK7 package. To install: sudo add-apt-repository ppa:webupd8team/java sudo apt-get update sudo apt-get install oracle-jdk7-installer And to uninstall: sudo apt-get remove oracle-jdk7-installer And to verify your installation: java -version java version "1.7.0_51" Java(TM) SE Runtime Environment (build 1.7.0_51-b13) Java HotSpot(TM) 64-Bit Server VM (build 22.0-b10, mixed mode) And to verify the web browser installation: http://java.com/en/download/installed.jsp Verified Java Version Congratulations! You have the recommended Java installed (1.7.0_51). And to update: If for some reason, the Java version in use is not 1.7.0, you can try to run the following command: sudo update-java-alternatives -s java-7-oracle To Install and Set in environment variable: To...