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

Configuring URL Encoding on Tomcat Application Server

Application servers may have different settings for character encodings. We strongly recommend UTF-8 where possible. By default, Tomcat uses ISO-8859-1 character encoding when decoding URLs received from a browser. This can cause problems when Confluence's encoding is UTF-8, and you are using international characters in the names of attachments or pages. To configure the URL encoding in Tomcat: Step 1 - Configure connector: Edit conf/server.xml and find the line where the Coyote HTTP Connector is defined. It will look something like this, possibly with more parameters: < Connector port = "8080" /> Add a URIEncoding="UTF-8" property to the connector: < Connector port = "8080" protocol = "HTTP/1.1"      connectionTimeout = "20000"      redirectPort = "8443"      URIEncoding = "UTF-8" /> If you are using mod_jk you should appl

Set Up Nginx Load Balancing

About Load Balancing Loadbalancing is a useful mechanism to distribute incoming traffic around several capable Virtual Private servers. By apportioning the processing mechanism to several machines, redundancy is provided to the application -- ensuring fault tolerance and heightened stability. The Round Robin algorithm for load balancing sends visitors to one of a set of IPs. At its most basic level Round Robin, which is fairly easy to implement, distributes server load without implementing considering more nuanced factors like server response time and the visitors’ geographic region. Setup The steps in this tutorial require the user to have root privileges on your VPS. Prior to setting up nginx loadbalancing, you should have nginx installed on your VPS. You can install it quickly with apt-get: sudo apt-get install nginx Upstream Module In order to set up a round robin load balancer, we will need to use the nginx upstream module. We will incorporate the conf