Sunday 15 May 2016

session sharing in tomcat cluster environment using memcache session manager

memcached-session-manager is a tomcat session manager that keeps sessions in memcached, for highly available, scalable and fault tolerant web applications. It supports both sticky and non-sticky configurations, and is currently working with tomcat 6.x, 7.x and 8.x. For sticky sessions session failover (tomcat crash) is supported, for non-sticky sessions this is the default (a session is served by default by different tomcats for different requests). Also memcached failover (memcached crash) is supported via migration of sessions. There shall also be no single point of failure, so when a memcached fails the session will not be lost (but either be available in tomcat or in another memcached).




\
How it Works:
User u1 send request to load balancer which have configured multiple server as 
cluster.suppose request r1 goes to tomcat t1 which create a session s1 with host name
and save it memcache server.

When the next request comes from same user with session id s1 it is directed to tomcat t1 
because of stickty session and help to reduced call to memcache server.

If tomcat t1 is down due to any reason any further request will be directed to tomcat t2 but it 
does not have user session or request may fails ,what it do is it get session from memcache server
which is centeral cache store for tomcat cluster. 
<Context>
  ...
  <Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager"
    memcachedNodes="n1:host1.yourdomain.com:11211,n2:host2.yourdomain.com:11211"
    failoverNodes="n1"
    requestUriIgnorePattern=".*\.(ico|png|gif|jpg|css|js)$"
    transcoderFactoryClass="de.javakaffee.web.msm.serializer.kryo.KryoTranscoderFactory"
    />
</Context>
Reference
https://github.com/magro/memcached-session-manager/wiki/SetupAndConfiguration
https://github.com/magro/memcached-session-manager
Sample Server
https://github.com/magro/memcached-session-manager/tree/master/samples

No comments:

Post a Comment