Suggested Pages

Saturday, August 4, 2012

Sticky Sessions

Sticky Sessions or Session Affinity

Sticky Sessions or Session Affinity means that incoming requests with the same session are routed to the same Tomcat worker.

Load Balancer

A load-balancer tracks HTTP requests and it dispatches the request to the appropriate node.

Load Balancer and Session Replication

Using a load balancer with session affinity, when a session is created on a node of the cluster, every future request will be sent and served by the same node.
Session replication is solved at this way: each request for a session will be handled by the same node. If the node dies, the session will be lost and the client has to login again into the system and starts a new session. Actually with load balancer and session affinity, you cannot replicate HTTP session.

modjk and sticky session

In the following snippet of code you can see an example of workers.properties to be configured on conf dir of Apache HTTP.

conf/workers.properties
# Define list of workers that will be used
# for mapping requests
worker.list=loadbalancer,status

# Define Node1
# modify the host as your host IP or DNS name.
worker.node1.port=8009
worker.node1.host=node1.mydomain.com 
worker.node1.type=ajp13
worker.node1.lbfactor=1
worker.node1.cachesize=10

# Define Node2
# modify the host as your host IP or DNS name.
worker.node2.port=8009
worker.node2.host=node2.mydomain.com
worker.node2.type=ajp13
worker.node2.lbfactor=1
worker.node2.cachesize=10

# Load-balancing behaviour
worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=node1,node2
worker.loadbalancer.sticky_session=1


# Status worker for managing load balancer
worker.status.type=status

No comments :

Post a Comment

Suggested Pages