View Full Version : Session maintenance on Hardware load balancing in tomcat...

14-10-2008, 01:55

I have a hardware load balancer in front on 2 identical instances of Tomcat servers (lets say Ins1 and Ins2). Lets say that Ins1 has 10 connections serving currently, and it is brought down.

My problem is that those 10 users will be kicked out, and they need to redo their work since Ins2 has no clue about it... I had used mod_jk or something similar when I used to approach a similar problem with my software load balancer in my previous project.

Anyway, I figured that knowledge is useless since I'm now dealing with a H/W LB, and it works differently. I checked with a few network experts and they say that unless the application can handle it, moving sessions from a dead instance to a live instance is not possible. Can anyone point out any approach I can take to solve my problem?

Thank you!
- M

14-10-2008, 08:27
Dear M,

I doubt there is much of a difference between a hardware load balancer and a software load balancer, unless your software load balancer was designed to be an integral part of your previous application.

The people you talked to are right; the application needs to support session sharing between the nodes. There are two observations that lead from there.

Lucky for you, Tomcat supports session sharing (http://tomcat.apache.org/tomcat-6.0-doc/cluster-howto.html), as documented on their home page.
Your web application needs to be written to only store serializable objects in the session.

The former is simply a matter of configuring it and testing it.

The latter may be a bigger issue. In my experience Java developers are very sloppy with the use of the serializable marker interface (http://java.sun.com/javase/6/docs/api/java/io/Serializable.html). If you start seeing NotSerializableException (http://java.sun.com/javase/6/docs/api/java/io/NotSerializableException.html)s, you have to review the Java code to track down and fix any non-seralizable classes. This is why you cannot store database connections and temp files in JSP Sessions, they make no sense in a clustered environment.

Oh, and let us know what pitfalls you run into. I will have to start using that for Java-monitor too. :-)

Kees Jan

14-10-2008, 15:07
Thank you for the nice reply!

I shall keep you updated on what happens next :)