Session Affinity/Sticky Session:
if you have many instances of tomcat (eg: tomcat1 & tomcat2) and you start session on tomcat1, the subsequent requests will be forwarded to tomcat1 as long as tomcat1 running an up (you never reach tomcat2). It means that if tomcat1 now is down, then your subsequent request will be forwarded to tomcat2, with a different session (a new session created at tomcat1 for you). This is not very good because if your application responding on tomcat1, then moved to tomcat2, session data will be lost. Usually Sticky session is achieved in simple load balancing of Apache server in front of tomcat servers.
Session replication, means you will have the same session id regardless of your first or subsequent requests served by tomcat1 or tomcat2. It means that you session will be duplicated on both tomcat1 and tomcat2. Sometimes you served by tomcat1, sometimes you served tomcat2, although none of them is down. Usually this is achieved when tomcat cluster is created.
<%@page language="java" %>
Session serviced by tomcat1
|Session ID||<%= session.getId() %>|
|Created on||<%= session.getCreationTime() %>|
Open a browser to http://
Click a number of times, you should stay with the same instance (sticky session working)
Shutdown an instance
- Retest using the browser and hopefully it should pickup the other instance but have the same session ID
session_id varchar(100) not null primay key,
valid_session char(1) not null,
max_inactive int not null,
last_access bigint not null,
1. Enable the Web Application as distributable
We need to make the our web application distribuable. its simple add
Entries in conf/server.xml filefor all instances.
Note: the port in bold is the one you need to change for each instance
hereManager tag define the delta manager. Delta manager meansreplicateto all instances.
Tomcat Clustering use the Apache Tribes communication framework. This group commnicationframeworkis responsible for dynamicmembership(usingmulticast) , send andreceivethe session delta information usinguni-cast(normal TCP connection).
This is Membership definition. here address is multicast address. we can pick any address from Class D address range (18.104.22.168 to 22.214.171.124)and any port number.
Each and every tomcat send the heart beat signal to multicast address inperiodic(frequency) interval. all other tomcat whose joined the multicast address they canreceivethese signals and add the membership to the cluster. if heat beat signal is notrevivesomeparticularinterval(dropTime) from any one of the tomcat, then we need to consider that tomcat is failed.
All tomcat instances which is part of the clustering, should have same multicast address and port number.
here sender use the PooledParallelSender have pooled connections to use the send the session informationconcurrently. so its speedup the session replication process.
here we define which port Receiver can bind and used for receiving the session replicate information. here two properties are important. address and port. here address is ur system IP address and port is any unused port. hereaddress=”auto” its automatically pick the system IP address.
we have some interceptor
TcpFailureDetector-Its ensure that instance are dead. In some case multicast messages are delayed, all tomcat instances are think about that tomcat is dead. but this interceptor to make tcp unicast to failed tomcat and ensure that instances is actually failed or not.
another important listener is JvmRouteSessionIDBinderListener.
3. Enable Multicast routing: –
here eth0 is myEthernetinterface. so changeaccordingto your interface
4.Backup Manager :-