The Apache Tomcat 5.5 Servlet/JSP Container - Clustering/Session Replication HOW-TO

| # The Apache Tomcat 5.5 Servlet/JSP Container |

# The Apache Tomcat 5.5 Servlet/JSP Container ## Clustering/Session Replication HOW-TO |
Quick Start
To run session replication in your Tomcat 5.5 container, the following steps should be completed: All your session attributes must implement `java.io.Serializable` Uncomment the `Cluster` element in server.xml Uncomment the `Valve(ReplicationValve)` element in server.xml If your Tomcat instances are running on the same machine, make sure the `tcpListenPort` attribute is unique for each instance. Make sure your `web.xml` has the `<distributable/>` element or set at your `<Context distributable="true" />` Make sure that jvmRoute attribute is set at your Engine `<Engine name="Catalina" jvmRoute="node01" >` Make sure that all nodes have the same time and sync with NTP service! Make sure that your loadbalancer is configured for sticky session mode. Load balancing can be achieved through many techniques, as seen in the Load Balancing chapter. Note: Remember that your session state is tracked by a cookie, so your URL must look the same from the out side otherwise, a new session will be created. Note: Clustering support currently requires the JDK version 1.4 or later.
Overview
> To enable session replication in Tomcat, three different paths can be followed to achieve the exact same thing: Using session persistence, and saving the session to a shared file system (PersistenceManager + FileStore) Using session persistence, and saving the session to a shared database (PersistenceManager + JDBCStore) Using in-memory-replication, using the SimpleTcpCluster that ships with Tomcat 5 (server/lib/catalina-cluster.jar) In this release of session replication, Tomcat performs an all-to-all replication of session state. This is an algorithm that is only efficient when the clusters are small. For large clusters, the next release will support a primary-secondary session replication where the session will only be stored at one or maybe two backup servers. Currently you can use the domain worker attribute (mod_jk > 1.2.8) to build cluster partitions with the potential of very scaleable cluster solution. In order to keep the network traffic down in an all-to-all environment, you can split your cluster into smaller groups. This can be easily achieved by using different multicast addresses for the different groups. A very simple setup would look like this:
>             DNS Round Robin
>                    |
>              Load Balancer
>               /           \
>           Cluster1      Cluster2
>           /     \        /     \
>       Tomcat1 Tomcat2  Tomcat3 Tomcat4
What is important to mention here, is that session replication is only the beginning of clustering. Another popular concept used to implement clusters is farming, ie, you deploy your apps only to one server, and the cluster will distribute the deployments across the entire cluster. This is all capabilities that can go into with the FarmWarDeployer (s. cluster example at `server.xml`) In the next section will go deeper into how session replication works and how to configure it.
How it Works
To make it easy to understand how clustering works, We are gonna take you through a series of scenarios. In the scenario we only plan to use two tomcat instances `TomcatA` and `TomcatB`. We will cover the following sequence of events: `TomcatA` starts up `TomcatB` starts up (Wait that TomcatA start is complete) `TomcatA` receives a request, a session `S1` is created. `TomcatA` crashes `TomcatB` receives a request for session `S1` `TomcatA` starts up `TomcatA` receives a request, invalidate is called on the session (`S1`) `TomcatB` receives a request, for a new session (`S2`) `TomcatA` The session `S2` expires due to inactivity. Ok, now that we have a good sequence, we will take you through exactly what happens in the session repliction code `TomcatA` starts up Tomcat starts up using the standard start up sequence. When the Host object is created, a cluster object is associated with it. When the contexts are parsed, if the distributable element is in place in web.xml Tomcat asks the Cluster class (in this case `SimpleTcpCluster`) to create a manager for the replicated context. So with clustering enabled, distributable set in web.xml Tomcat will create a `DeltaManager` for that context instead of a `StandardManager`. The cluster class will start up a membership service (multicast) and a replication service (tcp unicast). More on the architecture further down in this document. `TomcatB` starts up When TomcatB starts up, it follows the same sequence as TomcatA did with one exception. The cluster is started and will establish a membership (TomcatA,TomcatB). TomcatB will now request the session state from a server that already exists in the cluster, in this case TomcatA. TomcatA responds to the request, and before TomcatB starts listening for HTTP requests, the state has been transferred from TomcatA to TomcatB. In case TomcatA doesn't respond, TomcatB will time out after 60 seconds, and issue a log entry. The session state gets transferred for each web application that has distributable in its web.xml. Note: To use session replication efficiently, all your tomcat instances should be configured the same. `TomcatA` receives a request, a session `S1` is created. The request coming in to TomcatA is treated exactly the same way as without session replication. The action happens when the request is completed, the `ReplicationValve` will intercept the request before the response is returned to the user. At this point it finds that the session has been modified, and it uses TCP to replicata the session to TomcatB. Once the serialized data has been handed off to the operating systems TCP logic, the request returns to the user, back through the valve pipeline. For each request the entire session is replicated, this allows code that modifies attributes in the session without calling setAttribute or removeAttribute to be replicated. a useDirtyFlag configuration parameter can be used to optimize the number of times a session is replicated. `TomcatA` crashes When TomcatA crashes, TomcatB receives a notification that TomcatA has dropped out of the cluster. TomcatB removes TomcatA from its membership list, and TomcatA will no longer be notified of any changes that occurs in TomcatB. The load balancer will redirect the requests from TomcatA to TomcatB and all the sessions are current. `TomcatB` receives a request for session `S1` Nothing exciting, TomcatB will process the request as any other request. `TomcatA` starts up Upon start up, before TomcatA starts taking new request and making itself available to it will follow the start up sequence described above 1) 2). It will join the cluster, contact TomcatB for the current state of all the sessions. And once it receives the session state, it finishes loading and opens its HTTP/mod_jk ports. So no requests will make it to TomcatA until it has received the session state from TomcatB. `TomcatA` receives a request, invalidate is called on the session (`S1`) The invalidate is call is intercepted, and the session is queued with invalidated sessions. When the request is complete, instead of sending out the session that has changed, it sends out an "expire" message to TomcatB and TomcatB will invalidate the session as well. `TomcatB` receives a request, for a new session (`S2`) Same scenario as in step 3) `TomcatA` The session `S2` expires due to inactivity. The invalidate is call is intercepted the same was as when a session is invalidated by the user, and the session is queued with invalidated sessions. At this point, the invalidet session will not be replicated across until another request comes through the system and checks the invalid queue. Phuuuhh! :) Membership Clustering membership is established using very simple multicast pings. Each Tomcat instance will periodically send out a multicast ping, in the ping message the instance will broad cast its IP and TCP listen port for replication. If an instance has not received such a ping within a given timeframe, the member is considered dead. Very simple, and very effective! Of course, you need to enable multicasting on your system. TCP Replication Once a multicast ping has been received, the member is added to the cluster Upon the next replication request, the sending instance will use the host and port info and establish a TCP socket. Using this socket it sends over the serialized data. The reason I choose TCP sockets is because it has built in flow control and guaranteed delivery. So I know, when I send some data, it will make it there :) Distributed locking and pages using frames Tomcat does not keep session instances in sync across the cluster. The implementation of such logic would be to much overhead and cause all kinds of problems. If your client accesses the same session simultanously using multiple requests, then the last request will override the other sessions in the cluster.
Cluster Architecture
> Component Levels:
>              Server
>                |
>              Service
>                |
>              Engine
>                |  \
>                |  --- Cluster --*
>                |
>              Host
>                |
>              ------
>             /      \
>          Cluster    Context(1-N)
>             |             \
>             |             -- Manager
>             |                   \
>             |                   -- DeltaManager
>             |
>          -----------------------------
>          |          |         |       \
>        Receiver    Sender   Membership  \
>          \                               -- Valve
>          -- SocketReplicationListener    |      \
>          -- ReplicationListener          |       -- ReplicationValve
>                                          |       -- JvmRouteBinderValve
>                                          |
>                                          -- LifecycleListener
>                                          |
>                                          -- ClusterListener
>                                          |      \
>                                          |       -- ClusterSessionListener
>                                          |       -- JvmRouteSessionIDBinderListener
>                                          |
>                                          -- Deployer
>                                                 \
>                                                  -- FarmWarDeployer
>        Sender
>         \
>         -- ReplicationTransmitter
>                  |
>                  ---------
>                           \
>                        IDataSender
>                               \
>                               |
>                               --- (sync)
>                               |  \
>                               |   -- PooledSocketSender   (pooled)
>                               |   -- SockerSender         (synchronous)
>                               |
>                               --- (async)
>                                  \
>                                   -- AsyncSocketSender     (asynchronous)
>                                   -- FastAsyncSocketSender (fastasyncqueue)
Cluster Configuration
> The cluster configuration is described in the sample server.xml file. What is worth to mention is that the attributes starting with mcastXXX are for the membership multicast ping, and the attributes starting with tcpXXX are for the actual TCP replication. The membership is established by all the tomcat instances are sending broadcast messages on the same multicast IP and port. The TCP listen port, is the port where the session replication is received from other members. The replication valve is used to find out when the request has been completed and initiate the replication. One of the most important performance considerations is the synchronous (pooled or not pooled) versus asynchronous replication mode. In a synchronous replication mode the request doesn't return until the replicated session has been sent over the wire and reinstantiated on all the other cluster nodes. There are two settings for synchronous replication. Pooled or not pooled. Not pooled (ie replicationMode="fastasnycqueue" or "synchronous") means that all the replication request are sent over a single socket. Using synchronous mode can potentially becomes a bottleneck when a lot of messages generated, You can overcome this bottleneck by setting replicationMode="pooled" but then you worker threads blocks with replication . What is recommended here is to increase the number of threads that handle incoming replication request. This is the tcpThreadCount property in the cluster section of server.xml. The pooled setting means that we are using multiple sockets, hence increases the performance. Asynchronous replication, should be used if you have sticky sessions until fail over, then your replicated data is not time crucial, but the request time is, at this time leave the tcpThreadCount to be number-of-nodes-1. During async replication, the request is returned before the data has been replicated. async replication yields shorter request times, and synchronous replication guarantees the session to be replicated before the request returns. The parameter "replicationMode" has four different settings: "pooled", "synchronous", "asynchronous" and "fastasyncqueue"
> Simple Cluster Configuration
> > Simple one line configuration
> >        <Server                 port="8011"
> >                            shutdown="SHUTDOWN" >
> >         <GlobalNamingResources>
> >         <Resource              name="UserDatabase" auth="Container"
> >                                type="org.apache.catalina.UserDatabase"
> >                         description="User database that can be updated and saved"
> >                             factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
> >                             pathname="conf/tomcat-users.xml" />
> >       </GlobalNamingResources>
> >         <Service              name="Catalina">
> >             <Connector        port="9012"
> >                           protocol="AJP/1.3"
> >             <Connector         port="9013"
> >                          maxThreads="100"
> >                     minSpareThreads="4"
> >                     maxSpareThreads="4"
> >             />
> >             <Engine            name="Catalina"
> >                        defaultHost="localhost"
> >                             jvmRoute="node1">
> >             <Realm        className="org.apache.catalina.realm.UserDatabaseRealm"
> >                        resourceName="UserDatabase" />
> >                 <Host          name="localhost"
> >                             appBase="webapps">
> >                  <Cluster className="org.apache.catalina.cluster.tcp.SimpleTcpCluster"/>
> >                 </Host>
> >             </Engine>
> >         </Service>
> >     </Server>
> > The default mode configuration setup a fastasyncqueue mode cluster configuration with following parameters: Open Membership receiver at 228.0.0.4 and send to multicast udp port 8012 Send membership every 1 sec and drop member after 30sec. Open message receiver at default ip interface at first free port between 8015 and 8019. Receiver message with SocketReplicationListener Configure a ReplicationTransmitter with fastasyncqueue sender mode. Add ClusterSessionListener and ReplicationValve. NOTE: Use this configuration when you need very quick a test cluster with at your developer machine. You can change the default attributes from cluster sub elements. Use following cluster attribute prefixes sender., receiver., service., manager., valve. and listener.. Example configure cluster at windows laptop with network connection and change receiver port range
> >     <Cluster                 className="org.apache.catalina.cluster.tcp.SimpleTcpCluster"
> >               service.mcastBindAddress="127.0.0.1"
> >                 receiver.tcpListenPort="9070"
> >              receiver.tcpListenMaxPort="9075" />
> > WARNING: When you add you sub elements, there overwrite the defaults complete. Example configure cluster with cluster failover jsessionid support. In this case you need also the defaultmode Cluster listener ClusterSessionListener and ReplicationValve.
> >     <Cluster                 className="org.apache.catalina.cluster.tcp.SimpleTcpCluster"
> >               service.mcastBindAddress="127.0.0.1"
> >                 receiver.tcpListenPort="9070"
> >              receiver.tcpListenMaxPort="9075" >
> >            <ClusterListener  className="org.apache.catalina.cluster.session.ClusterSessionListener" />
> >            <ClusterListener  className="org.apache.catalina.cluster.session.JvmRouteSessionIDBinderListener" />
> >            <Valve            className="org.apache.catalina.cluster.tcp.ReplicationValve"
> >                                 filter=".*\.gif;.*\.js;.*\.css;.*\.png;.*\.jpeg;.*\.jpg;.*\.htm;.*\.html;.*\.txt;"
> >                       primaryIndicator="true" />
> >     	   <Valve            className="org.apache.catalina.cluster.session.JvmRouteBinderValve"
> >     	                      enabled="true"  />
> >     <Cluster/>
> Simple Engine Cluster Configuration for all hosts
> > Simple one line engine configuration
> >        <Server                 port="8011"
> >                            shutdown="SHUTDOWN" >
> >         <GlobalNamingResources>
> >         <Resource              name="UserDatabase" auth="Container"
> >                                type="org.apache.catalina.UserDatabase"
> >                         description="User database that can be updated and saved"
> >                             factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
> >                             pathname="conf/tomcat-users.xml" />
> >       </GlobalNamingResources>
> >         <Service              name="Catalina">
> >             <Connector        port="9012"
> >                           protocol="AJP/1.3"
> >             <Connector         port="9013"
> >                          maxThreads="100"
> >                     minSpareThreads="4"
> >                     maxSpareThreads="4"
> >             />
> >             <Engine            name="Catalina"
> >                        defaultHost="localhost"
> >                             jvmRoute="node01">
> >             <Realm        className="org.apache.catalina.realm.UserDatabaseRealm"
> >                        resourceName="UserDatabase" />
> >             <Cluster      className="org.apache.catalina.cluster.tcp.SimpleTcpCluster"/>
> >                 <Host          name="localhost"
> >                             appBase="webapps"/>
> >             </Engine>
> >         </Service>
> >     </Server>
> See default mode configuration description as simple host cluster example before.
> Complex Cluster Configuration
> > Example Configure cluster with complete sub elements. Activate this node as master farm delopyer. Message receiver is NIO based ReplicationListener with six parallel worker threads.
> >            <Server                 port="8011"
> >                            shutdown="SHUTDOWN" >
> >         <GlobalNamingResources>
> >         <Resource              name="UserDatabase" auth="Container"
> >                                type="org.apache.catalina.UserDatabase"
> >                         description="User database that can be updated and saved"
> >                             factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
> >                             pathname="conf/tomcat-users.xml" />
> >       </GlobalNamingResources>
> >         <Service              name="Catalina">
> >             <Connector        port="9012"
> >                           protocol="AJP/1.3"
> >             <Connector         port="9013"
> >                          maxThreads="100"
> >                     minSpareThreads="4"
> >                     maxSpareThreads="4"
> >             />
> >             <Engine            name="Catalina"
> >                        defaultHost="localhost"
> >                             jvmRoute="node01">
> >             <Realm        className="org.apache.catalina.realm.UserDatabaseRealm"
> >                        resourceName="UserDatabase" />
> >                 <Host          name="localhost"
> >                             appBase="webapps">
> >                     <Cluster                  className="org.apache.catalina.cluster.tcp.SimpleTcpCluster"
> >                                            doClusterLog="true"
> >                                          clusterLogName="clusterlog"
> >                                       manager.className="org.apache.catalina.cluster.session.DeltaManager"
> >                        manager.expireSessionsOnShutdown="false"
> >                    manager.notifyListenersOnReplication="false"
> >             manager.notifySessionListenersOnReplication="false"
> >                                 manager.sendAllSessions="false"
> >                             manager.sendAllSessionsSize="500"
> >                         manager.sendAllSessionsWaitTime="20">
> >                       <Membership
> >                                               className="org.apache.catalina.cluster.mcast.McastService"
> >                                               mcastAddr="228.0.0.4"
> >                                        mcastBindAddress="127.0.0.1"
> >                                      mcastClusterDomain="d10"
> >                                               mcastPort="45564"
> >                                          mcastFrequency="1000"
> >                                           mcastDropTime="30000"/>
> >                       <Receiver
> >                                                className="org.apache.catalina.cluster.tcp.ReplicationListener"
> >                                         tcpListenAddress="auto"
> >                                            tcpListenPort="9015"
> >                                       tcpSelectorTimeout="100"
> >                                           tcpThreadCount="6"
> >                       <Sender
> >                                                className="org.apache.catalina.cluster.tcp.ReplicationTransmitter"
> >                                          replicationMode="fastasyncqueue"
> >                             doTransmitterProcessingStats="true"
> >                                        doProcessingStats="true"
> >                                           doWaitAckStats="true"
> >                                            queueTimeWait="true"
> >                                             queueDoStats="true"
> >                                           queueCheckLock="true"
> >                                               ackTimeout="15000"
> >                                               waitForAck="true"
> >                                         keepAliveTimeout="80000"
> >                                 keepAliveMaxRequestCount="-1"/>
> >                       <Valve                   className="org.apache.catalina.cluster.tcp.ReplicationValve"
> >                                                   filter=".*\.gif;.*\.js;.*\.css;.*\.png;.*\.jpeg;.*\.jpg;.*\.htm;.*\.html;.*\.txt;"
> >                                         primaryIndicator="true" />
> >                       <Valve                    className="org.apache.catalina.cluster.session.JvmRouteBinderValve"
> >                                                  enabled="true" />
> >                       <ClusterListener         className="org.apache.catalina.cluster.session.ClusterSessionListener" />
> >                       <ClusterListener         className="org.apache.catalina.cluster.session.JvmRouteSessionIDBinderListener" />
> >                       <Deployer                className="org.apache.catalina.cluster.deploy.FarmWarDeployer"
> >                                                 tempDir="${catalina.base}/war-temp"
> >                                               deployDir="${catalina.base}/war-deploy/"
> >                                                watchDir="${catalina.base}/war-listen/"
> >                                            watchEnabled="true"/>
> >                       </Cluster>
> >                 </Host>
> >             </Engine>
> >         </Service>
> >     </Server>
> Cluster Configuration for ReplicationTransmitter
> > List of Attributes
> > Attribute | Description | Default value
> > --- | --- | ---
> > replicationMode | replication mode (synchronous, pooled, asynchronous or fastasyncqueue) | `pooled`
> > processSenderFrequency | Control the sender keepalive status and drop sender socket connection after timeout is reached. Check every processSenderFrequency value engine background ticks. | `2`
> > compress | compress bytes before sending (consume memory, but reduce network traffic - GZIP) | `false`
> > ackTimeout | acknowledge timeout and only usefull it waitForAck is true | `15000`
> > waitForAck | Wait for ack after data send | `false`
> > autoConnect | is sender disabled, fork a new socket | `false`
> > doTransmitterProcessingStats | create processing time stats | `false`
> > Example to get statistic information, wait for ack at every message send and transfer at compressed mode
> >         <Sender
> >           className="org.apache.catalina.cluster.tcp.ReplicationTransmitter"
> >           replicationMode="fastasyncqueue"
> >           compress="true"
> >           doTransmitterProcessingStats="true"
> >           ackTimeout="15000"
> >           waitForAck="true"
> >           autoConnect="false"/>
> Cluster Configuration for ReplicationTransmitter (fastayncqueue - mode)
> > List of Attributes
> > Attribute | Description | Default value
> > --- | --- | ---
> > keepAliveTimeout | active socket keep alive timeout | `60000`
> > keepAliveMaxRequestCount | max request over this socket | `-1`
> > doProcessingStats | create Processing time stats | `false`
> > doWaitAckStats | create waitAck time stats | `false`
> > resend | resend message after failure, can overwrite at message | `false`
> > queueDoStats | activated queue stats | `false`
> > queueCheckLock | check to lost locks | `false`
> > queueAddWaitTimeout | queue add wait time (tomcat connector thread waits) | `10000`
> > queueRemoveWaitTimeout | queue remove wait time (queue thread waits) | `30000`
> > maxQueueLength | max queue length (default without limit) | `-1`
> > threadPriority | change queue thread priority (1-10 ; 5 is normal) | `5`
> > Example to get a lot of statistic information and no wait for ACK
> >         <Sender
> >           className="org.apache.catalina.cluster.tcp.ReplicationTransmitter"
> >           replicationMode="fastasyncqueue"
> >           doTransmitterProcessingStats="true"
> >           doProcessingStats="true"
> >           queueTimeWait="true"
> >           queueDoStats="true"
> >           queueCheckLock="true"
> >           waitForAck="false"
> >           autoConnect="false"
> >           keepAliveTimeout="320000"
> >           keepAliveMaxRequestCount="-1"/>
> Cluster Configuration for ReplicationTransmitter ( asynchronous - mode)
> > List of Attributes
> > Attribute | Description | Default value
> > --- | --- | ---
> > keepAliveTimeout | active socket keep alive timeout | `60000`
> > keepAliveMaxRequestCount | max request over this socket | `-1`
> > doProcessingStats | create Processing time stats | `false`
> > doWaitAckStats | create waitAck time stats | `false`
> > resend | resend message after failure, can overwrite at message | `false`
> > Example to get a processing statistic information, resend after failure and wait for ACK
> >         <Sender
> >           className="org.apache.catalina.cluster.tcp.ReplicationTransmitter"
> >           replicationMode="asynchronous"
> >           doProcessingStats="true"
> >           doWaitAckStats="true"
> >           waitForAck="true"
> >           ackTimeout="30000"
> >           resend="true"
> >           keepAliveTimeout="320000"
> >           keepAliveMaxRequestCount="-1"/>
> Cluster Configuration for ReplicationTransmitter ( synchronous - mode)
> > List of Attributes
> > Attribute | Description | Default value
> > --- | --- | ---
> > keepAliveTimeout | active socket keep alive timeout | `60000`
> > keepAliveMaxRequestCount | max request over this socket | `-1`
> > doProcessingStats | create Processing time stats | `false`
> > doWaitAckStats | create waitAck time stats | `true`
> > resend | resend message after failure, can overwrite at message | `false`
> > Example to get a no processing statistic information, no wait for ACK, after 10000 request renew socket and autoconnect before first request is send.
> >         <Sender
> >           className="org.apache.catalina.cluster.tcp.ReplicationTransmitter"
> >           replicationMode="synchronous"
> >           autoConnect="true"
> >           keepAliveTimeout="-1"
> >           keepAliveMaxRequestCount="100000"/>
> Cluster Configuration for ReplicationTransmitter ( pooled - mode)
> > List of Attributes
> > Attribute | Description | Default value
> > --- | --- | ---
> > keepAliveTimeout | active socket keep alive timeout | `60000`
> > keepAliveMaxRequestCount | max request over this socket | `-1`
> > maxPoolSocketLimit | max pooled sockets (Sender Sockets) | `25`
> > resend | resend message after failure, can overwrite at message | `false`
> > Example to get a no processing statistic information, wait for ACK, after 10000 request renew socket, only 10 SockerSender available and autoconnect before first request is send.
> >         <Sender
> >           className="org.apache.catalina.cluster.tcp.ReplicationTransmitter"
> >           replicationMode="pooled"
> >           autoConnect="true"
> >           maxPoolSocketLimit="10"
> >           keepAliveTimeout="-1"
> >           keepAliveMaxRequestCount="10000"
> >           waitForAck="true" />
> Cluster Configuration for ReplicationTransmitter ( DeltaManager Attribute)
> > List of Attributes
> > Attribute | Description | Default value
> > --- | --- | ---
> > expireSessionsOnShutdown | When server stopped, expire all sessions also at backup nodes (only for testing) | `false`
> > maxActiveSessions | Number of active sessions. (Default is no limit) | `-1`
> > notifyListenersOnReplication | Notify application session listener to session creation and expiring events at backup nodes | `true`
> > notifySessionListenersOnReplication | Notify application session listener to attribute changes at backup nodes | `true`
> > stateTransferTimeout | Timeout that session state transfer is complete. Is attribute `stateTransferTimeout == -1` then application wait that other node send the complete session state | `60`
> > sendAllSessions | Flag to send sessions as splited blocks | `true`
> > sendAllSessionsSize | Number of serialize sessions inside a send block session message. Only useful when `sendAllSessions==false` | `1000`
> > sendAllSessionsWaitTime | wait time between two session send blocks. | `2000`
> > sendClusterDomainOnly | Send all session messages only to member inside same cluster domain (value od Membership attribute mcastClusterDomain). Also don't handle session messages from other domains. | `true`
> > stateTimestampDrop | DeltaManager queued Sessions messages when send GET_ALL_SESSION to other node. with stateTimestampDrop all messages before state transfer message creation date (find session) are dropped. Only other GET_ALL_SESSION events are handle with date before state transfer message. | `true`
> > Example send all sessions at separate blocks. Serialize and send 100 session inside one block. Wait maximale two minutes before the complete backup sessions are loaded inside tomcat boot process. Between send blocks wait 5 secs to transfers the session block to other node. This save memory when you use the async modes with queues.
> >         <Cluster className="org.apache.catalina.tcp.SimpleTcpCluster"
> >           managerClassName="org.apache.catalina.cluster.session.DeltaManager"
> >           manager.stateTransferTimeout="120"
> >           manager.sendAllSessions="false"
> >           manager.sendAllSessionsSize="100"
> >           manager.sendAllSessionsWaitTime="5000"
> >           "/>
> Note: As Cluster.defaultMode=true you can configure the manager attributes with prefix manager.. Note: With Cluster.setProperty(<String>,<String>) you can modify attributes for all register managers. The method exists as MBeans operation.
> Bind session after crash to failover node
> > As you configure more then two nodes at same cluster for backup, most loadbalancer send don't all your requests after failover to the same node. The JvmRouteBinderValve handle tomcat jvmRoute takeover using mod_jk module after node failure. After a node crashed the next request going to other cluster node. The JvmRouteBinderValve now detect the takeover and rewrite the jsessionid information to the backup cluster node. After the next response all client request goes direct to the backup node. The change sessionid send also to all other cluster nodes. Well, now the session stickyness work directly to the backup node, but traffic don't go back too restarted cluster nodes! As jsessionid was created by cookie, the change JSESSIONID cookie resend with next response. You must add JvmRouteBinderValve and the corresponding cluster message listener JvmRouteSessionIDBinderListener. As you add the new listener you must also add the default ClusterSessionListener that receiver the normal cluster messages.
> >     <Cluster className="org.apache.catalina.tcp.SimpleTcpCluster" >
> >     ...
> >          <Valve className="org.apache.catalina.cluster.session.JvmRouteBinderValve"
> >                    enabled="true" sessionIdAttribute="takeoverSessionid"/>
> >          <ClusterListener className="org.apache.catalina.cluster.session.JvmRouteSessionIDBinderListener" />
> >          <ClusterListener className="org.apache.catalina.cluster.session.ClusterSessionListener" />
> >     ...
> >     <Cluster>
> Hint: With attribute sessionIdAttribute you can change the request attribute name that included the old session id. Default attribuite name is org.apache.catalina.cluster.session.JvmRouteOrignalSessionID. Trick: You can enable this mod_jk turnover mode via JMX before you drop a node to all backup nodes! Set enable true on all JvmRouteBinderValve backups, disable worker at mod_jk and then drop node and restart it! Then enable mod_jk Worker and disable JvmRouteBinderValves again. This use case means that only requested session are migrated.
Monitoring your Cluster with JMX
> Monitoring is a very important question when you use a cluster. Some of the cluster objects are JMX MBeans Add the following parameter to your startup script with Java 5:
>     set CATALINA_OPTS=\
>     -Dcom.sun.management.jmxremote \
>     -Dcom.sun.management.jmxremote.port=%my.jmx.port% \
>     -Dcom.sun.management.jmxremote.ssl=false \
>     -Dcom.sun.management.jmxremote.authenticate=false
> 3. Activate JMX with JDK 1.4: Install the compat package Install the mx4j-tools.jar at common/lib (use the same mx4j version as your tomcat release) Configure a MX4J JMX HTTP Adaptor at your AJP Connector
>        <Connector port="${AJP.PORT}"
>           handler.list="mx"
>           mx.enabled="true"
>           mx.httpHost="${JMX.HOST}"
>           mx.httpPort="${JMX.PORT}"
>           protocol="AJP/1.3" />
> Start your tomcat and look with your browser to http://${JMX.HOST}:${JMX.PORT} With the connector parameter `mx.authMode="basic" mx.authUser="tomcat" mx.authPassword="strange"` you can control the access! List of Cluster Mbeans
> Name | Description | MBean ObjectName - Engine | MBean ObjectName - Host
> --- | --- | --- | ---
> Cluster | The complete cluster element | `type=Cluster` | `type=Cluster,host=${HOST}`
> ClusterSender | Configuration and stats of the sender infrastructure | `type=ClusterSender` | `type=ClusterSender,host=${HOST}`
> ClusterReceiver | Configuration and stats of the recevier infrastructure | `type=ClusterReceiver` | `type=ClusterReceiver,host=${HOST}`
> ClusterMembership | Configuration and stats of the membership infrastructure | `type=ClusterMembership` | `type=ClusterMembership,host=${HOST}`
> IDataSender | For every cluster member it exist a sender mbeans. It exists speziall MBeans to all replication modes | `type=IDataSender, senderAddress=${MEMBER.SENDER.IP}, senderPort=${MEMBER.SENDER.PORT}` | `type=IDataSender,host=${HOST}, senderAddress=${MEMBER.SENDER.IP}, senderPort=${MEMBER.SENDER.PORT}`
> DeltaManager | This manager control the sessions and handle session replication | `type=Manager,path=${APP.CONTEXT.PATH}, host=${HOST}` | `type=Manager,path=${APP.CONTEXT.PATH}, host=${HOST}`
> ReplicationValve | This valve control the replication to the backup nodes | `type=Valve,name=ReplicationValve` | `type=Valve,name=ReplicationValve,host=${HOST}`
> JvmRouteBinderValve | This is a cluster fallback valve to change the Session ID to the current tomcat jvmroute. | `type=Valve,name=JvmRouteBinderValve, path=${APP.CONTEXT.PATH}` | `type=Valve,name=JvmRouteBinderValve,host=${HOST}, path=${APP.CONTEXT.PATH}`
FAQ
Please see the clustering section of the FAQ.
Copyright © 1999-2006, Apache Software Foundation