2

I am struggling with configuration of session replication in Tomcat cluster. Ramki's articles about Tomcat Clustering helped me a lot. Load balancing and sticky session works well.

SessionIDs are replicated, but only IDs. Session attributes are not, they changed only on primary node. Apache Tribes replication of full session is missing.

My environment: Oracle Linux 6.6, Tomcat 8.0.20, JRE 7u55-b13

Apache httpd.conf

LoadModule    jk_module  modules/mod_jk.so
JkWorkersFile conf/workers.properties

JkLogFile     logs/mod_jk.log
JkLogLevel    emerg
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
JkOptions     +ForwardKeySize +ForwardURICompat -ForwardDirectories
JkRequestLogFormat     "%w %V %T"

JkMount /status stat
JkMount /* balancer

JkMount /uzel1* uzel1
JkMount /uzel2* uzel2
JkMount /uzel3* uzel3

workers.properties

worker.list=balancer,stat

worker.uzel1.type=ajp13
worker.uzel1.port=8021
worker.uzel1.host=localhost
worker.uzel1.lbfactor=10

worker.uzel2.type=ajp13
worker.uzel2.port=8022
worker.uzel2.host=localhost
worker.uzel2.lbfactor=10

worker.uzel3.type=ajp13
worker.uzel3.port=8023
worker.uzel3.host=localhost
worker.uzel3.lbfactor=10

worker.balancer.type=lb
worker.balancer.balance_workers=uzel1,uzel2,uzel3

worker.stat.type=status

Tomcat1 (uzel1) server.xml (other nodes uses increased port numbers, e.g. 8022, 4001, etc.)

<Connector port="8021" protocol="AJP/1.3" redirectPort="8441" />
<Engine name="Catalina" defaultHost="localhost" jvmRoute="uzel1">
    <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster" channelSendOptions="8">
      <Manager className="org.apache.catalina.ha.session.DeltaManager" expireSessionsOnShutdown="false"
               notifyListenersOnReplication="true"/>
      <Channel className="org.apache.catalina.tribes.group.GroupChannel">
        <Membership className="org.apache.catalina.tribes.membership.McastService"
                    address="224.0.0.4"
                    port="45564"
                    frequency="500"
                    dropTime="3000"/>
        <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
                  address="auto"
                  port="4001"
                  autoBind="100"
                  selectorTimeout="5000"
                  maxThreads="6"/>
        <Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
          <Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/>
        </Sender>
        <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>
        <Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/>
      </Channel>
      <Valve className="org.apache.catalina.ha.tcp.ReplicationValve"
             filter=""/>
      <Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve"/>
      <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>
    </Cluster>

When new session is created, this is logged in uzel1/catalina.out

12-Mar-2015 15:56:53.540 FINE [ajp-nio-8021-exec-1] org.apache.catalina.ha.session.DeltaManager.sendCreateSession Manager [localhost#] send new session (6BB91945986B0B389849887109F97864.uzel1)
12-Mar-2015 15:56:53.542 FINE [ajp-nio-8021-exec-1] org.apache.catalina.ha.session.DeltaManager.createSession Created a DeltaSession with Id [6BB91945986B0B389849887109F97864.uzel1] Total count=1
12-Mar-2015 15:56:53.547 FINE [ajp-nio-8021-exec-1] org.apache.catalina.ha.session.DeltaManager.requestCompleted Manager [localhost#]: create session message [6BB91945986B0B389849887109F97864.uzel1] delta request.

Tomcat2 writes this to uzel2/catalina.out

12-Mar-2015 15:56:53.545 FINE [Tribes-Task-Receiver-5] org.apache.catalina.ha.session.DeltaManager.messageReceived Manager [localhost#]: Received SessionMessage of type=(SESSION-MODIFIED) from [org.apache.catalina.tribes.membership.MemberImpl[tcp://{10, 0, 1, 61}:4001,{10, 0, 1, 61},4001, alive=193202, securePort=-1, UDP Port=-1, id={67 84 5 -55 -55 -93 72 -27 -88 19 109 68 117 4 -82 56 }, payload={}, command={}, domain={}, ]]
12-Mar-2015 15:56:53.546 FINE [Tribes-Task-Receiver-5] org.apache.catalina.ha.session.DeltaManager.handleSESSION_CREATED Manager [localhost#]: received session [6BB91945986B0B389849887109F97864.uzel1] created.
12-Mar-2015 15:56:53.554 FINE [Tribes-Task-Receiver-6] org.apache.catalina.ha.session.DeltaManager.messageReceived Manager [localhost#]: Received SessionMessage of type=(SESSION-DELTA) from [org.apache.catalina.tribes.membership.MemberImpl[tcp://{10, 0, 1, 61}:4001,{10, 0, 1, 61},4001, alive=193202, securePort=-1, UDP Port=-1, id={67 84 5 -55 -55 -93 72 -27 -88 19 109 68 117 4 -82 56 }, payload={}, command={}, domain={}, ]]
12-Mar-2015 15:56:53.555 FINE [Tribes-Task-Receiver-6] org.apache.catalina.ha.session.DeltaManager.handleSESSION_DELTA Manager [localhost#]: received session [6BB91945986B0B389849887109F97864.uzel1] delta.

So second node knows about new session. However, it does not replicate it.

No TCP packet was caugth at ports 4001-4003 with

#tcpdump -nnq dst port 4001 or dst port 4002 or dst port 4003 

Do you have any ideas what should be checked, dumped, examined?

Any help is appreciated!

Leos

2
  • Make sure your web.xml has the <distributable/> element – Federico Sierra Mar 12 '15 at 17:54
  • 1
    @Federico: Forgot to tell. Yes, this element was included in web.xml. – nautil2 Mar 13 '15 at 8:20
2

Solved!

There were two problems

Session replication works with Apache Tomcat example servlet SessionExample, accessible at http://host:port/examples/servlets/servlet/SessionExample

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.