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...

Tomcat Clustering: Loadbalancing with mod_jk and Apache

We already see how to run multiple tomcat instance in a single machine in my previous blog ( http://kmlsarwar.blogspot.com/2014/08/multiple-tomcat-instances-on-single.html ). In this post we will see how to configure load balancing with mod_jk and Apache on Ubuntu. Suppose we have two hosts, node1 and node2 . Node1 runs an Apache and a Tomcat instance. On node2 we’ve got another Tomcat. A browser will connect to the host that’s running the Apache. Since the load on a single server running a web application can be pretty severe, we’re going to share the burden of serving servlets with multiple hosts (in our case two hosts). And we’re going to make mod_jk to do that for us. Steps to Implement Virtual Host/Loadbalancer Concept in this Scenario: Install Apache httpd Web Server  Install mod_jk connector  Configure JK Connector  Configure Apache httpd server, apply loadbalancer concepts Step One—Install Apache We can install Apache web ser...