This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes Session Migration Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Session Migration" Watch "Session Migration" New topic
Author

Session Migration

Mark Garland
Ranch Hand

Joined: Nov 11, 2006
Posts: 226
Hi all,

Just something I wondered about using sessions in a distributed environment...

Lets say we have 4 servers behind a load balancer.
My first request is load balanced onto Server1, and a session is created there for me.
My second request is load balanced onto Server4, and my session is migrated across.

My question is how does Server4 know to look on Server1?
Does is just send out a broadcast message? - isn't this inefficient for large server farms?
Does the load balancer keep track, and so match the session id to the server name (so it tells 4 to ask 1 for the session)?

Thanks in advance,

MG


28/06/06 - SCJP - 69%, 05/06/07 - SCWCD - 92%, 28/02/08 - IBM DB2 v9 Fundamentals (Exam 730) - 87%, 18/11/08 - IBM DB2 v9 DBA (Exam 731) - 89%, 26/02/11 - SCBCD - 88%
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
I think there is nothing in the specification related to this.Vendors are free to implement this feature the way they want.

SRV 7.7.2 of servlet specification says about this.
[ May 24, 2007: Message edited by: Rahul Bhattacharjee ]

Rahul Bhattacharjee
LinkedIn - Blog
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

There are different ways to load balance.

One route is to use sticky session at the load balancer level.
In this case the router/load balancer insures that a user is always sent to the same node in your cluster. How it works is product specific.

Another approach is to use session replication at the servlet container level.
In this case, each time a session is changed in any node, the change is broadcasted to all the other nodes in the cluster. This method is a little less efficient than the first because all the nodes have to maintain the complete session information for every client using the app but it gives you the advantage of being able to start and stop any node in the cluster without having to worry about interrupting service to any of your clients.

Some larger apps use a combination of the two so they can enjoy the benefits of both.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
With WebSphere we used a third option: saving the session to the database. WS provides several levers to control when and how much is written. With sticky sessions to make reading the database as rare as possible we are still able to stop and start servers in the cluster one at a time.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Stan James:
With WebSphere we used a third option: saving the session to the database. WS provides several levers to control when and how much is written. With sticky sessions to make reading the database as rare as possible we are still able to stop and start servers in the cluster one at a time.


This is also a trade offs as it forces a database hit for any request that uses session variables.
Tomcat's session manager can be configured to do this as well.
 
Consider Paul's rocket mass heater.
 
subject: Session Migration
 
Similar Threads
Load Balancer
web session migration
Defining load balancer in websphere network deployment 7
Tomcat Load balancing using mod_rewrite
JMS Load Balancing In Websphere V7.0