[66] | 1 | <html><head><META http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><title>Apache Tomcat 6.0 - Clustering/Session Replication HOW-TO</title><meta value="Filip Hanik" name="author"><meta value="fhanik@apache.org" name="email"><meta value="Peter Rossbach" name="author"><meta value="pero@apache.org" name="email"></head><body vlink="#525D76" alink="#525D76" link="#525D76" text="#000000" bgcolor="#ffffff"><table cellspacing="0" width="100%" border="0"><!--PAGE HEADER--><tr><td><!--PROJECT LOGO--><a href="http://tomcat.apache.org/"><img border="0" alt=" |
---|
| 2 | The Apache Tomcat Servlet/JSP Container |
---|
| 3 | " align="right" src="./images/tomcat.gif"></a></td><td><font face="arial,helvetica,sanserif"><h1>Apache Tomcat 6.0</h1></font></td><td><!--APACHE LOGO--><a href="http://www.apache.org/"><img border="0" alt="Apache Logo" align="right" src="./images/asf-logo.gif"></a></td></tr></table><table cellspacing="4" width="100%" border="0"><!--HEADER SEPARATOR--><tr><td colspan="2"><hr size="1" noshade></td></tr><tr><!--LEFT SIDE NAVIGATION--><td nowrap="true" valign="top" width="20%"><p><strong>Links</strong></p><ul><li><a href="index.html">Docs Home</a></li><li><a href="http://wiki.apache.org/tomcat/FAQ">FAQ</a></li></ul><p><strong>User Guide</strong></p><ul><li><a href="introduction.html">1) Introduction</a></li><li><a href="setup.html">2) Setup</a></li><li><a href="appdev/index.html">3) First webapp</a></li><li><a href="deployer-howto.html">4) Deployer</a></li><li><a href="manager-howto.html">5) Manager</a></li><li><a href="realm-howto.html">6) Realms and AAA</a></li><li><a href="security-manager-howto.html">7) Security Manager</a></li><li><a href="jndi-resources-howto.html">8) JNDI Resources</a></li><li><a href="jndi-datasource-examples-howto.html">9) JDBC DataSources</a></li><li><a href="class-loader-howto.html">10) Classloading</a></li><li><a href="jasper-howto.html">11) JSPs</a></li><li><a href="ssl-howto.html">12) SSL</a></li><li><a href="ssi-howto.html">13) SSI</a></li><li><a href="cgi-howto.html">14) CGI</a></li><li><a href="proxy-howto.html">15) Proxy Support</a></li><li><a href="mbeans-descriptor-howto.html">16) MBean Descriptor</a></li><li><a href="default-servlet.html">17) Default Servlet</a></li><li><a href="cluster-howto.html">18) Clustering</a></li><li><a href="balancer-howto.html">19) Load Balancer</a></li><li><a href="connectors.html">20) Connectors</a></li><li><a href="monitoring.html">21) Monitoring and Management</a></li><li><a href="logging.html">22) Logging</a></li><li><a href="apr.html">23) APR/Native</a></li><li><a href="virtual-hosting-howto.html">24) Virtual Hosting</a></li><li><a href="aio.html">25) Advanced IO</a></li><li><a href="extras.html">26) Additional Components</a></li><li><a href="maven-jars.html">27) Mavenized</a></li></ul><p><strong>Reference</strong></p><ul><li><a href="RELEASE-NOTES.txt">Release Notes</a></li><li><a href="config/index.html">Configuration</a></li><li><a href="api/index.html">Javadocs</a></li><li><a href="http://tomcat.apache.org/connectors-doc/">JK 1.2 Documentation</a></li></ul><p><strong>Apache Tomcat Development</strong></p><ul><li><a href="building.html">Building</a></li><li><a href="changelog.html">Changelog</a></li><li><a href="http://wiki.apache.org/tomcat/TomcatVersions">Status</a></li><li><a href="developers.html">Developers</a></li><li><a href="architecture/index.html">Architecture</a></li><li><a href="funcspecs/index.html">Functional Specs.</a></li></ul></td><!--RIGHT SIDE MAIN BODY--><td align="left" valign="top" width="80%"><table cellspacing="4" width="100%" border="0"><tr><td valign="top" align="left"><h1>Apache Tomcat 6.0</h1><h2>Clustering/Session Replication HOW-TO</h2></td><td nowrap="true" valign="top" align="right"><small><a href="printer/cluster-howto.html"><img alt="Printer Friendly Version" border="0" src="./images/printer.gif"><br>print-friendly<br>version |
---|
| 4 | </a></small></td></tr></table><table cellpadding="2" cellspacing="0" border="0"><tr><td bgcolor="#525D76"><font face="arial,helvetica.sanserif" color="#ffffff"><a name="Important Note"><strong>Important Note</strong></a></font></td></tr><tr><td><blockquote> |
---|
| 5 | <p><b>You can also check the <a href="config/cluster.html">configuration reference documentation.</a></b> |
---|
| 6 | </p> |
---|
| 7 | </blockquote></td></tr></table><table cellpadding="2" cellspacing="0" border="0"><tr><td bgcolor="#525D76"><font face="arial,helvetica.sanserif" color="#ffffff"><a name="For the impatient"><strong>For the impatient</strong></a></font></td></tr><tr><td><blockquote> |
---|
| 8 | <p> |
---|
| 9 | Simply add <div align="left"><table border="0" cellpadding="0" cellspacing="4"><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#ffffff"><pre><Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/></pre></td><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr></table></div> |
---|
| 10 | to your <code><Engine></code> or your <code><Host></code> element to enable clustering. |
---|
| 11 | </p> |
---|
| 12 | <p> |
---|
| 13 | Using the above configuration will enable all-to-all session replication |
---|
| 14 | using the <code>DeltaManager</code> to replicate session deltas. By all-to-all we mean that the session gets replicated to all the other |
---|
| 15 | nodes in the cluster. This works great for smaller cluster but we don't recommend it for larger clusters(a lot of tomcat nodes). |
---|
| 16 | Also when using the delta manager it will replicate to all nodes, even nodes that don't have the application deployed.<br> |
---|
| 17 | To get around this problem, you'll want to use the BackupManager. This manager only replicates the session data to one backup |
---|
| 18 | node, and only to nodes that have the application deployed. Downside of the BackupManager: not quite as battle tested as the delta manager. |
---|
| 19 | <br> |
---|
| 20 | Here are some of the important default values:<br> |
---|
| 21 | 1. Multicast address is 228.0.0.4<br> |
---|
| 22 | 2. Multicast port is 45564 (the port and the address together determine cluster membership.<br> |
---|
| 23 | 3. The IP broadcasted is <code>java.net.InetAddress.getLocalHost().getHostAddress()</code> (make sure you don't broadcast 127.0.0.1, this is a common error)<br> |
---|
| 24 | 4. The TCP port listening for replication messages is the first available server socket in range <code>4000-4100</code><br> |
---|
| 25 | 5. Two listeners are configured <code>ClusterSessionListener</code> and <code>JvmRouteSessionIDBinderListener</code><br> |
---|
| 26 | 6. Two interceptors are configured <code>TcpFailureDetector</code> and <code>MessageDispatch15Interceptor</code><br> |
---|
| 27 | The following is the default cluster configuration:<br> |
---|
| 28 | <div align="left"><table border="0" cellpadding="0" cellspacing="4"><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#ffffff"><pre> |
---|
| 29 | <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster" |
---|
| 30 | channelSendOptions="8"> |
---|
| 31 | |
---|
| 32 | <Manager className="org.apache.catalina.ha.session.DeltaManager" |
---|
| 33 | expireSessionsOnShutdown="false" |
---|
| 34 | notifyListenersOnReplication="true"/> |
---|
| 35 | |
---|
| 36 | <Channel className="org.apache.catalina.tribes.group.GroupChannel"> |
---|
| 37 | <Membership className="org.apache.catalina.tribes.membership.McastService" |
---|
| 38 | address="228.0.0.4" |
---|
| 39 | port="45564" |
---|
| 40 | frequency="500" |
---|
| 41 | dropTime="3000"/> |
---|
| 42 | <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver" |
---|
| 43 | address="auto" |
---|
| 44 | port="4000" |
---|
| 45 | autoBind="100" |
---|
| 46 | selectorTimeout="5000" |
---|
| 47 | maxThreads="6"/> |
---|
| 48 | |
---|
| 49 | <Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter"> |
---|
| 50 | <Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/> |
---|
| 51 | </Sender> |
---|
| 52 | <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/> |
---|
| 53 | <Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/> |
---|
| 54 | </Channel> |
---|
| 55 | |
---|
| 56 | <Valve className="org.apache.catalina.ha.tcp.ReplicationValve" |
---|
| 57 | filter=""/> |
---|
| 58 | <Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve"/> |
---|
| 59 | |
---|
| 60 | <Deployer className="org.apache.catalina.ha.deploy.FarmWarDeployer" |
---|
| 61 | tempDir="/tmp/war-temp/" |
---|
| 62 | deployDir="/tmp/war-deploy/" |
---|
| 63 | watchDir="/tmp/war-listen/" |
---|
| 64 | watchEnabled="false"/> |
---|
| 65 | |
---|
| 66 | <ClusterListener className="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener"/> |
---|
| 67 | <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/> |
---|
| 68 | </Cluster> |
---|
| 69 | </pre></td><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr></table></div> |
---|
| 70 | </p> |
---|
| 71 | <p>Will cover this section in more detail later in this document.</p> |
---|
| 72 | </blockquote></td></tr></table><table cellpadding="2" cellspacing="0" border="0"><tr><td bgcolor="#525D76"><font face="arial,helvetica.sanserif" color="#ffffff"><a name="Cluster Basics"><strong>Cluster Basics</strong></a></font></td></tr><tr><td><blockquote> |
---|
| 73 | |
---|
| 74 | <p>To run session replication in your Tomcat 6.0 container, the following steps |
---|
| 75 | should be completed:</p> |
---|
| 76 | <ul> |
---|
| 77 | <li>All your session attributes must implement <code>java.io.Serializable</code></li> |
---|
| 78 | <li>Uncomment the <code>Cluster</code> element in server.xml</li> |
---|
| 79 | <li>If you have defined custom cluster valves, make sure you have the <code>ReplicationValve</code> defined as well under the Cluster element in server.xml</li> |
---|
| 80 | <li>If your Tomcat instances are running on the same machine, make sure the <code>tcpListenPort</code> |
---|
| 81 | attribute is unique for each instance, in most cases Tomcat is smart enough to resolve this on it's own by autodetecting available ports in the range 4000-4100</li> |
---|
| 82 | <li>Make sure your <code>web.xml</code> has the <code><distributable/></code> element |
---|
| 83 | or set at your <code><Context distributable="true" /></code></li> |
---|
| 84 | <li>If you are using mod_jk, make sure that jvmRoute attribute is set at your Engine <code><Engine name="Catalina" jvmRoute="node01" ></code> |
---|
| 85 | and that the jvmRoute attribute value matches your worker name in workers.properties</li> |
---|
| 86 | <li>Make sure that all nodes have the same time and sync with NTP service!</li> |
---|
| 87 | <li>Make sure that your loadbalancer is configured for sticky session mode.</li> |
---|
| 88 | </ul> |
---|
| 89 | <p>Load balancing can be achieved through many techniques, as seen in the |
---|
| 90 | <a href="balancer-howto.html">Load Balancing</a> chapter.</p> |
---|
| 91 | <p>Note: Remember that your session state is tracked by a cookie, so your URL must look the same from the out |
---|
| 92 | side otherwise, a new session will be created.</p> |
---|
| 93 | <p>Note: Clustering support currently requires the JDK version 1.5 or later.</p> |
---|
| 94 | <p>The Cluster module uses the Tomcat JULI logging framework, so you can configure logging |
---|
| 95 | through the regular logging.properties file. To track messages, you can enable logging on the key:<code>org.apache.catalina.tribes.MESSAGES</code></p> |
---|
| 96 | </blockquote></td></tr></table><table cellpadding="2" cellspacing="0" border="0"><tr><td bgcolor="#525D76"><font face="arial,helvetica.sanserif" color="#ffffff"><a name="Overview"><strong>Overview</strong></a></font></td></tr><tr><td><blockquote> |
---|
| 97 | |
---|
| 98 | <p>To enable session replication in Tomcat, three different paths can be followed to achieve the exact same thing:</p> |
---|
| 99 | <ol> |
---|
| 100 | <li>Using session persistence, and saving the session to a shared file system (PersistenceManager + FileStore)</li> |
---|
| 101 | <li>Using session persistence, and saving the session to a shared database (PersistenceManager + JDBCStore)</li> |
---|
| 102 | <li>Using in-memory-replication, using the SimpleTcpCluster that ships with Tomcat 6 (lib/catalina-tribes.jar + lib/catalina-ha.jar)</li> |
---|
| 103 | </ol> |
---|
| 104 | |
---|
| 105 | <p>In this release of session replication, Tomcat can perform an all-to-all replication of session state using the <code>DeltaManager</code> or |
---|
| 106 | perform backup replication to only one node using the <code>BackupManager</code>. |
---|
| 107 | The all-to-all replication is an algorithm that is only efficient when the clusters are small. For larger clusters, to use |
---|
| 108 | a primary-secondary session replication where the session will only be stored at one backup server simply setup the BackupManager. <br> |
---|
| 109 | Currently you can use the domain worker attribute (mod_jk > 1.2.8) to build cluster partitions |
---|
| 110 | with the potential of having a more scaleable cluster solution with the DeltaManager(you'll need to configure the domain interceptor for this). |
---|
| 111 | In order to keep the network traffic down in an all-to-all environment, you can split your cluster |
---|
| 112 | into smaller groups. This can be easily achieved by using different multicast addresses for the different groups. |
---|
| 113 | A very simple setup would look like this: |
---|
| 114 | </p> |
---|
| 115 | |
---|
| 116 | <div align="left"><table border="0" cellpadding="0" cellspacing="4"><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#ffffff"><pre> |
---|
| 117 | DNS Round Robin |
---|
| 118 | | |
---|
| 119 | Load Balancer |
---|
| 120 | / \ |
---|
| 121 | Cluster1 Cluster2 |
---|
| 122 | / \ / \ |
---|
| 123 | Tomcat1 Tomcat2 Tomcat3 Tomcat4 |
---|
| 124 | </pre></td><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr></table></div> |
---|
| 125 | |
---|
| 126 | <p>What is important to mention here, is that session replication is only the beginning of clustering. |
---|
| 127 | Another popular concept used to implement clusters is farming, ie, you deploy your apps only to one |
---|
| 128 | server, and the cluster will distribute the deployments across the entire cluster. |
---|
| 129 | This is all capabilities that can go into with the FarmWarDeployer (s. cluster example at <code>server.xml</code>)</p> |
---|
| 130 | <p>In the next section will go deeper into how session replication works and how to configure it.</p> |
---|
| 131 | |
---|
| 132 | </blockquote></td></tr></table><table cellpadding="2" cellspacing="0" border="0"><tr><td bgcolor="#525D76"><font face="arial,helvetica.sanserif" color="#ffffff"><a name="Cluster Information"><strong>Cluster Information</strong></a></font></td></tr><tr><td><blockquote> |
---|
| 133 | <p>Membership is established using multicast heartbeats. |
---|
| 134 | Hence, if you wish to subdivide your clusters, you can do this by |
---|
| 135 | changing the multicast IP address or port in the <code><Membership></code> element. |
---|
| 136 | </p> |
---|
| 137 | <p> |
---|
| 138 | The heartbeat contains the IP address of the Tomcat node and the TCP port that |
---|
| 139 | Tomcat listens to for replication traffic. All data communication happens over TCP. |
---|
| 140 | </p> |
---|
| 141 | <p> |
---|
| 142 | The <code>ReplicationValve</code> is used to find out when the request has been completed and initiate the |
---|
| 143 | replication, if any. Data is only replicated if the session has changed (by calling setAttribute or removeAttribute |
---|
| 144 | on the session). |
---|
| 145 | </p> |
---|
| 146 | <p> |
---|
| 147 | One of the most important performance considerations is the synchronous versus asynchronous replication. |
---|
| 148 | In a synchronous replication mode the request doesn't return until the replicated session has been |
---|
| 149 | sent over the wire and reinstantiated on all the other cluster nodes. |
---|
| 150 | Synchronous vs asynchronous is configured using the <code>channelSendOptions</code> |
---|
| 151 | flag and is an integer value. The default value for the <code>SimpleTcpCluster/DeltaManager</code> combo is |
---|
| 152 | 8, which is asynchronous. You can read more on the <a href="tribes/introduction.html">send flag(overview)</a> or the |
---|
| 153 | <a href="http://tomcat.apache.org/tomcat-6.0-doc/api/org/apache/catalina/tribes/Channel.html">send flag(javadoc)</a>. |
---|
| 154 | During async replication, the request is returned before the data has been replicated. async replication yields shorter |
---|
| 155 | request times, and synchronous replication guarantees the session to be replicated before the request returns. |
---|
| 156 | </p> |
---|
| 157 | </blockquote></td></tr></table><table cellpadding="2" cellspacing="0" border="0"><tr><td bgcolor="#525D76"><font face="arial,helvetica.sanserif" color="#ffffff"><a name="Bind session after crash to failover node"><strong>Bind session after crash to failover node</strong></a></font></td></tr><tr><td><blockquote> |
---|
| 158 | <p> |
---|
| 159 | If you are using mod_jk and not using sticky sessions or for some reasons sticky session don't |
---|
| 160 | work, or you are simply failing over, the session id will need to be modified as it previously contained |
---|
| 161 | the worker id of the previous tomcat (as defined by jvmRoute in the Engine element). |
---|
| 162 | To solve this, we will use the JvmRouteBinderValve. |
---|
| 163 | </p> |
---|
| 164 | <p> |
---|
| 165 | The JvmRouteBinderValve rewrites the session id to ensure that the next request will remain sticky |
---|
| 166 | (and not fall back to go to random nodes since the worker is no longer available) after a fail over. |
---|
| 167 | The valve rewrites the JSESSIONID value in the cookie with the same name. |
---|
| 168 | Not having this valve in place, will make it harder to ensure stickyness in case of a failure for the mod_jk module. |
---|
| 169 | </p> |
---|
| 170 | <p> |
---|
| 171 | By default, if no valves are configured, the JvmRouteBinderValve is added on. |
---|
| 172 | The cluster message listener called JvmRouteSessionIDBinderListener is also defined by default and is used to actually rewrite the |
---|
| 173 | session id on the other nodes in the cluster once a fail over has occurred. |
---|
| 174 | Remember, if you are adding your own valves or cluster listeners in server.xml then the defaults are no longer valid, |
---|
| 175 | make sure that you add in all the appropriate valves and listeners as defined by the default. |
---|
| 176 | </p> |
---|
| 177 | <p> |
---|
| 178 | <b>Hint:</b><br> |
---|
| 179 | With attribute <i>sessionIdAttribute</i> you can change the request attribute name that included the old session id. |
---|
| 180 | Default attribuite name is <i>org.apache.catalina.cluster.session.JvmRouteOrignalSessionID</i>. |
---|
| 181 | </p> |
---|
| 182 | <p> |
---|
| 183 | <b>Trick:</b><br> |
---|
| 184 | You can enable this mod_jk turnover mode via JMX before you drop a node to all backup nodes! |
---|
| 185 | Set enable true on all JvmRouteBinderValve backups, disable worker at mod_jk |
---|
| 186 | and then drop node and restart it! Then enable mod_jk Worker and disable JvmRouteBinderValves again. |
---|
| 187 | This use case means that only requested session are migrated. |
---|
| 188 | </p> |
---|
| 189 | |
---|
| 190 | |
---|
| 191 | |
---|
| 192 | </blockquote></td></tr></table><table cellpadding="2" cellspacing="0" border="0"><tr><td bgcolor="#525D76"><font face="arial,helvetica.sanserif" color="#ffffff"><a name="Configuration Example"><strong>Configuration Example</strong></a></font></td></tr><tr><td><blockquote> |
---|
| 193 | <div align="left"><table border="0" cellpadding="0" cellspacing="4"><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#ffffff"><pre> |
---|
| 194 | <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster" |
---|
| 195 | channelSendOptions="6"> |
---|
| 196 | |
---|
| 197 | <Manager className="org.apache.catalina.ha.session.BackupManager" |
---|
| 198 | expireSessionsOnShutdown="false" |
---|
| 199 | notifyListenersOnReplication="true" |
---|
| 200 | mapSendOptions="6"/> |
---|
| 201 | <!-- |
---|
| 202 | <Manager className="org.apache.catalina.ha.session.DeltaManager" |
---|
| 203 | expireSessionsOnShutdown="false" |
---|
| 204 | notifyListenersOnReplication="true"/> |
---|
| 205 | --> |
---|
| 206 | <Channel className="org.apache.catalina.tribes.group.GroupChannel"> |
---|
| 207 | <Membership className="org.apache.catalina.tribes.membership.McastService" |
---|
| 208 | address="228.0.0.4" |
---|
| 209 | port="45564" |
---|
| 210 | frequency="500" |
---|
| 211 | dropTime="3000"/> |
---|
| 212 | <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver" |
---|
| 213 | address="auto" |
---|
| 214 | port="5000" |
---|
| 215 | selectorTimeout="100" |
---|
| 216 | maxThreads="6"/> |
---|
| 217 | |
---|
| 218 | <Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter"> |
---|
| 219 | <Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/> |
---|
| 220 | </Sender> |
---|
| 221 | <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/> |
---|
| 222 | <Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/> |
---|
| 223 | <Interceptor className="org.apache.catalina.tribes.group.interceptors.ThroughputInterceptor"/> |
---|
| 224 | </Channel> |
---|
| 225 | |
---|
| 226 | <Valve className="org.apache.catalina.ha.tcp.ReplicationValve" |
---|
| 227 | filter=".*\.gif;.*\.js;.*\.jpg;.*\.png;.*\.htm;.*\.html;.*\.css;.*\.txt;"/> |
---|
| 228 | |
---|
| 229 | <Deployer className="org.apache.catalina.ha.deploy.FarmWarDeployer" |
---|
| 230 | tempDir="/tmp/war-temp/" |
---|
| 231 | deployDir="/tmp/war-deploy/" |
---|
| 232 | watchDir="/tmp/war-listen/" |
---|
| 233 | watchEnabled="false"/> |
---|
| 234 | |
---|
| 235 | <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/> |
---|
| 236 | </Cluster> |
---|
| 237 | </pre></td><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr></table></div> |
---|
| 238 | <p> |
---|
| 239 | Break it down!! |
---|
| 240 | </p> |
---|
| 241 | <div align="left"><table border="0" cellpadding="0" cellspacing="4"><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#ffffff"><pre> |
---|
| 242 | <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster" |
---|
| 243 | channelSendOptions="6"> |
---|
| 244 | </pre></td><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr></table></div> |
---|
| 245 | <p> |
---|
| 246 | The main element, inside this element all cluster details can be configured. |
---|
| 247 | The <code>channelSendOptions</code> is the flag that is attached to each message sent by the |
---|
| 248 | SimpleTcpCluster class or any objects that are invoking the SimpleTcpCluster.send method. |
---|
| 249 | The description of the send flags is available at <a href="http://tomcat.apache.org/tomcat-6.0-doc/api/org/apache/catalina/tribes/Channel.html"> |
---|
| 250 | our javadoc site</a> |
---|
| 251 | The <code>DeltaManager</code> sends information using the SimpleTcpCluster.send method, while the backup manager |
---|
| 252 | sends it itself directly through the channel. |
---|
| 253 | <br>For more info, Please visit the <a href="config/cluster.html">reference documentation</a> |
---|
| 254 | </p> |
---|
| 255 | <div align="left"><table border="0" cellpadding="0" cellspacing="4"><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#ffffff"><pre> |
---|
| 256 | <Manager className="org.apache.catalina.ha.session.BackupManager" |
---|
| 257 | expireSessionsOnShutdown="false" |
---|
| 258 | notifyListenersOnReplication="true" |
---|
| 259 | mapSendOptions="6"/> |
---|
| 260 | <!-- |
---|
| 261 | <Manager className="org.apache.catalina.ha.session.DeltaManager" |
---|
| 262 | expireSessionsOnShutdown="false" |
---|
| 263 | notifyListenersOnReplication="true"/> |
---|
| 264 | --> |
---|
| 265 | </pre></td><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr></table></div> |
---|
| 266 | <p> |
---|
| 267 | This is a template for the manager configuration that will be used if no manager is defined in the <Context> |
---|
| 268 | element. In Tomcat 5.x each webapp marked distributable had to use the same manager, this is no longer the case |
---|
| 269 | since Tomcat 6 you can define a manager class for each webapp, so that you can mix managers in your cluster. |
---|
| 270 | Obviously the managers on one node's application has to correspond with the same manager on the same application on the other node. |
---|
| 271 | If no manager has been specified for the webapp, and the webapp is marked <distributable/> Tomcat will take this manager configuration |
---|
| 272 | and create a manager instance cloning this configuration. |
---|
| 273 | <br>For more info, Please visit the <a href="config/cluster-manager.html">reference documentation</a> |
---|
| 274 | </p> |
---|
| 275 | <div align="left"><table border="0" cellpadding="0" cellspacing="4"><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#ffffff"><pre> |
---|
| 276 | <Channel className="org.apache.catalina.tribes.group.GroupChannel"> |
---|
| 277 | </pre></td><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr></table></div> |
---|
| 278 | <p> |
---|
| 279 | The channel element is <a href="tribes/introduction.html">Tribes</a>, the group communication framework |
---|
| 280 | used inside Tomcat. This element encapsulates everything that has to do with communication and membership logic. |
---|
| 281 | <br>For more info, Please visit the <a href="config/cluster-channel.html">reference documentation</a> |
---|
| 282 | </p> |
---|
| 283 | <div align="left"><table border="0" cellpadding="0" cellspacing="4"><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#ffffff"><pre> |
---|
| 284 | <Membership className="org.apache.catalina.tribes.membership.McastService" |
---|
| 285 | address="228.0.0.4" |
---|
| 286 | port="45564" |
---|
| 287 | frequency="500" |
---|
| 288 | dropTime="3000"/> |
---|
| 289 | </pre></td><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr></table></div> |
---|
| 290 | <p> |
---|
| 291 | Membership is done using multicasting. Please note that Tribes also supports static memberships using the |
---|
| 292 | <code>StaticMembershipInterceptor</code> if you want to extend your membership to points beyond multicasting. |
---|
| 293 | The address attribute is the multicast address used and the port is the multicast port. These two together |
---|
| 294 | create the cluster separation. If you want a QA cluster and a production cluster, the easiest config is to |
---|
| 295 | have the QA cluster be on a separate multicast address/port combination the the production cluster.<br> |
---|
| 296 | The membership component broadcasts TCP adress/port of itselt to the other nodes so that communication between |
---|
| 297 | nodes can be done over TCP. Please note that the address being broadcasted is the one of the |
---|
| 298 | <code>Receiver.address</code> attribute. |
---|
| 299 | <br>For more info, Please visit the <a href="config/cluster-membership.html">reference documentation</a> |
---|
| 300 | </p> |
---|
| 301 | <div align="left"><table border="0" cellpadding="0" cellspacing="4"><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#ffffff"><pre> |
---|
| 302 | <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver" |
---|
| 303 | address="auto" |
---|
| 304 | port="5000" |
---|
| 305 | selectorTimeout="100" |
---|
| 306 | maxThreads="6"/> |
---|
| 307 | </pre></td><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr></table></div> |
---|
| 308 | <p> |
---|
| 309 | In tribes the logic of sending and receiving data has been broken into two functional components. The Receiver, as the name suggests |
---|
| 310 | is responsible for receiving messages. Since the Tribes stack is thread less, (a popular improvement now adopted by other frameworks as well), |
---|
| 311 | there is a thread pool in this component that has a maxThreads and minThreads setting.<br> |
---|
| 312 | The address attribute is the host address that will be broadcasted by the membership component to the other nodes. |
---|
| 313 | <br>For more info, Please visit the <a href="config/cluster-receiver.html">reference documentation</a> |
---|
| 314 | </p> |
---|
| 315 | <div align="left"><table border="0" cellpadding="0" cellspacing="4"><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#ffffff"><pre> |
---|
| 316 | |
---|
| 317 | <Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter"> |
---|
| 318 | <Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/> |
---|
| 319 | </Sender> |
---|
| 320 | </pre></td><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr></table></div> |
---|
| 321 | <p> |
---|
| 322 | The sender component, as the name indicates is responsible for sending messages to other nodes. |
---|
| 323 | The sender has a shell component, the <code>ReplicationTransmitter</code> but the real stuff done is done in the |
---|
| 324 | sub component, <code>Transport</code>. |
---|
| 325 | Tribes support having a pool of senders, so that messages can be sent in parallel and if using the NIO sender, |
---|
| 326 | you can send messages concurrently as well.<br> |
---|
| 327 | Concurrently means one message to multiple senders at the same time and Parallel means multiple messages to multiple senders |
---|
| 328 | at the same time. |
---|
| 329 | <br>For more info, Please visit the <a href="config/cluster-sender.html">reference documentation</a> |
---|
| 330 | </p> |
---|
| 331 | <div align="left"><table border="0" cellpadding="0" cellspacing="4"><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#ffffff"><pre> |
---|
| 332 | <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/> |
---|
| 333 | <Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/> |
---|
| 334 | <Interceptor className="org.apache.catalina.tribes.group.interceptors.ThroughputInterceptor"/> |
---|
| 335 | </Channel> |
---|
| 336 | </pre></td><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr></table></div> |
---|
| 337 | <p> |
---|
| 338 | Tribes uses a stack to send messages through. Each element in the stack is called an interceptor, and works much like the valves do |
---|
| 339 | in the Tomcat servlet container. |
---|
| 340 | Using interceptors, logic can be broken into more managable pieces of code. The interceptors configured above are:<br> |
---|
| 341 | TcpFailureDetector - verifies crashed members through TCP, if multicast packets get dropped, this interceptor protects against false positives, |
---|
| 342 | ie the node marked as crashed even though it still is alive and running.<br> |
---|
| 343 | MessageDispatch15Interceptor - dispatches messages to a thread (thread pool) to send message asynchrously.<br> |
---|
| 344 | ThroughputInterceptor - prints out simple stats on message traffic.<br> |
---|
| 345 | Please note that the order of interceptors is important. the way they are defined in server.xml is the way they are represented in the |
---|
| 346 | channel stack. Think of it as a linked list, with the head being the first most interceptor and the tail the last. |
---|
| 347 | <br>For more info, Please visit the <a href="config/cluster-interceptor.html">reference documentation</a> |
---|
| 348 | </p> |
---|
| 349 | <div align="left"><table border="0" cellpadding="0" cellspacing="4"><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#ffffff"><pre> |
---|
| 350 | <Valve className="org.apache.catalina.ha.tcp.ReplicationValve" |
---|
| 351 | filter=".*\.gif;.*\.js;.*\.jpg;.*\.png;.*\.htm;.*\.html;.*\.css;.*\.txt;"/> |
---|
| 352 | </pre></td><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr></table></div> |
---|
| 353 | <p> |
---|
| 354 | The cluster uses valves to track requests to web applications, we've mentioned the ReplicationValve and the JvmRouteBinderValve above. |
---|
| 355 | The <Cluster> element itself is not part of the pipeline in Tomcat, instead the cluster adds the valve to its parent container. |
---|
| 356 | If the <Cluster> elements is configured in the <Engine> element, the valves get added to the engine and so on. |
---|
| 357 | <br>For more info, Please visit the <a href="config/cluster-valve.html">reference documentation</a> |
---|
| 358 | </p> |
---|
| 359 | <div align="left"><table border="0" cellpadding="0" cellspacing="4"><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#ffffff"><pre> |
---|
| 360 | <Deployer className="org.apache.catalina.ha.deploy.FarmWarDeployer" |
---|
| 361 | tempDir="/tmp/war-temp/" |
---|
| 362 | deployDir="/tmp/war-deploy/" |
---|
| 363 | watchDir="/tmp/war-listen/" |
---|
| 364 | watchEnabled="false"/> |
---|
| 365 | </pre></td><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr></table></div> |
---|
| 366 | <p> |
---|
| 367 | The default tomcat cluster supports farmed deployment, ie, the cluster can deploy and undeploy applications on the other nodes. |
---|
| 368 | The state of this component is currently in flux but will be addressed soon. There was a change in the deployment algorithm |
---|
| 369 | between Tomcat 5.0 and 5.5 and at that point, the logic of this component changed to where the deploy dir has to match the |
---|
| 370 | webapps directory. |
---|
| 371 | <br>For more info, Please visit the <a href="config/cluster-deployer.html">reference documentation</a> |
---|
| 372 | </p> |
---|
| 373 | <div align="left"><table border="0" cellpadding="0" cellspacing="4"><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#ffffff"><pre> |
---|
| 374 | <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/> |
---|
| 375 | </Cluster> |
---|
| 376 | </pre></td><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr></table></div> |
---|
| 377 | <p> |
---|
| 378 | Since the SimpleTcpCluster itself is a sender and receiver of the Channel object, components can register themselves as listeners to |
---|
| 379 | the SimpleTcpCluster. The listener above <code>ClusterSessionListener</code> listens for DeltaManager replication messages |
---|
| 380 | and applies the deltas to the manager that in turn applies it to the session. |
---|
| 381 | <br>For more info, Please visit the <a href="config/cluster-listener.html">reference documentation</a> |
---|
| 382 | </p> |
---|
| 383 | |
---|
| 384 | </blockquote></td></tr></table><table cellpadding="2" cellspacing="0" border="0"><tr><td bgcolor="#525D76"><font face="arial,helvetica.sanserif" color="#ffffff"><a name="Cluster Architecture"><strong>Cluster Architecture</strong></a></font></td></tr><tr><td><blockquote> |
---|
| 385 | |
---|
| 386 | <p><b>Component Levels:</b> |
---|
| 387 | <div align="left"><table border="0" cellpadding="0" cellspacing="4"><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#ffffff"><pre> |
---|
| 388 | Server |
---|
| 389 | | |
---|
| 390 | Service |
---|
| 391 | | |
---|
| 392 | Engine |
---|
| 393 | | \ |
---|
| 394 | | --- Cluster --* |
---|
| 395 | | |
---|
| 396 | Host |
---|
| 397 | | |
---|
| 398 | ------ |
---|
| 399 | / \ |
---|
| 400 | Cluster Context(1-N) |
---|
| 401 | | \ |
---|
| 402 | | -- Manager |
---|
| 403 | | \ |
---|
| 404 | | -- DeltaManager |
---|
| 405 | | -- BackupManager |
---|
| 406 | | |
---|
| 407 | --------------------------- |
---|
| 408 | | \ |
---|
| 409 | Channel \ |
---|
| 410 | ----------------------------- \ |
---|
| 411 | | \ |
---|
| 412 | Interceptor_1 .. \ |
---|
| 413 | | \ |
---|
| 414 | Interceptor_N \ |
---|
| 415 | ----------------------------- \ |
---|
| 416 | | | | \ |
---|
| 417 | Receiver Sender Membership \ |
---|
| 418 | -- Valve |
---|
| 419 | | \ |
---|
| 420 | | -- ReplicationValve |
---|
| 421 | | -- JvmRouteBinderValve |
---|
| 422 | | |
---|
| 423 | -- LifecycleListener |
---|
| 424 | | |
---|
| 425 | -- ClusterListener |
---|
| 426 | | \ |
---|
| 427 | | -- ClusterSessionListener |
---|
| 428 | | -- JvmRouteSessionIDBinderListener |
---|
| 429 | | |
---|
| 430 | -- Deployer |
---|
| 431 | \ |
---|
| 432 | -- FarmWarDeployer |
---|
| 433 | |
---|
| 434 | |
---|
| 435 | </pre></td><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr></table></div> |
---|
| 436 | </p> |
---|
| 437 | |
---|
| 438 | </blockquote></td></tr></table><table cellpadding="2" cellspacing="0" border="0"><tr><td bgcolor="#525D76"><font face="arial,helvetica.sanserif" color="#ffffff"><a name="How it Works"><strong>How it Works</strong></a></font></td></tr><tr><td><blockquote> |
---|
| 439 | <p>To make it easy to understand how clustering works, We are gonna take you through a series of scenarios. |
---|
| 440 | In the scenario we only plan to use two tomcat instances <code>TomcatA</code> and <code>TomcatB</code>. |
---|
| 441 | We will cover the following sequence of events:</p> |
---|
| 442 | |
---|
| 443 | <ol> |
---|
| 444 | <li><code>TomcatA</code> starts up</li> |
---|
| 445 | <li><code>TomcatB</code> starts up (Wait that TomcatA start is complete)</li> |
---|
| 446 | <li><code>TomcatA</code> receives a request, a session <code>S1</code> is created.</li> |
---|
| 447 | <li><code>TomcatA</code> crashes</li> |
---|
| 448 | <li><code>TomcatB</code> receives a request for session <code>S1</code></li> |
---|
| 449 | <li><code>TomcatA</code> starts up</li> |
---|
| 450 | <li><code>TomcatA</code> receives a request, invalidate is called on the session (<code>S1</code>)</li> |
---|
| 451 | <li><code>TomcatB</code> receives a request, for a new session (<code>S2</code>)</li> |
---|
| 452 | <li><code>TomcatA</code> The session <code>S2</code> expires due to inactivity.</li> |
---|
| 453 | </ol> |
---|
| 454 | |
---|
| 455 | <p>Ok, now that we have a good sequence, we will take you through exactly what happens in the session repliction code</p> |
---|
| 456 | |
---|
| 457 | <ol> |
---|
| 458 | <li><b><code>TomcatA</code> starts up</b> |
---|
| 459 | <p> |
---|
| 460 | Tomcat starts up using the standard start up sequence. When the Host object is created, a cluster object is associated with it. |
---|
| 461 | When the contexts are parsed, if the distributable element is in place in web.xml |
---|
| 462 | Tomcat asks the Cluster class (in this case <code>SimpleTcpCluster</code>) to create a manager |
---|
| 463 | for the replicated context. So with clustering enabled, distributable set in web.xml |
---|
| 464 | Tomcat will create a <code>DeltaManager</code> for that context instead of a <code>StandardManager</code>. |
---|
| 465 | The cluster class will start up a membership service (multicast) and a replication service (tcp unicast). |
---|
| 466 | More on the architecture further down in this document. |
---|
| 467 | </p><p></p> |
---|
| 468 | </li> |
---|
| 469 | <li><b><code>TomcatB</code> starts up</b> |
---|
| 470 | <p> |
---|
| 471 | When TomcatB starts up, it follows the same sequence as TomcatA did with one exception. |
---|
| 472 | The cluster is started and will establish a membership (TomcatA,TomcatB). |
---|
| 473 | TomcatB will now request the session state from a server that already exists in the cluster, |
---|
| 474 | in this case TomcatA. TomcatA responds to the request, and before TomcatB starts listening |
---|
| 475 | for HTTP requests, the state has been transferred from TomcatA to TomcatB. |
---|
| 476 | In case TomcatA doesn't respond, TomcatB will time out after 60 seconds, and issue a log |
---|
| 477 | entry. The session state gets transferred for each web application that has distributable in |
---|
| 478 | its web.xml. Note: To use session replication efficiently, all your tomcat instances should be |
---|
| 479 | configured the same. |
---|
| 480 | </p><p></p> |
---|
| 481 | </li> |
---|
| 482 | <li><B><code>TomcatA</code> receives a request, a session <code>S1</code> is created.</B> |
---|
| 483 | <p> |
---|
| 484 | The request coming in to TomcatA is treated exactly the same way as without session replication. |
---|
| 485 | The action happens when the request is completed, the <code>ReplicationValve</code> will intercept |
---|
| 486 | the request before the response is returned to the user. |
---|
| 487 | At this point it finds that the session has been modified, and it uses TCP to replicata the |
---|
| 488 | session to TomcatB. Once the serialized data has been handed off to the operating systems TCP logic, |
---|
| 489 | the request returns to the user, back through the valve pipeline. |
---|
| 490 | For each request the entire session is replicated, this allows code that modifies attributes |
---|
| 491 | in the session without calling setAttribute or removeAttribute to be replicated. |
---|
| 492 | a useDirtyFlag configuration parameter can be used to optimize the number of times |
---|
| 493 | a session is replicated. |
---|
| 494 | </p><p></p> |
---|
| 495 | |
---|
| 496 | </li> |
---|
| 497 | <li><b><code>TomcatA</code> crashes</b> |
---|
| 498 | <p> |
---|
| 499 | When TomcatA crashes, TomcatB receives a notification that TomcatA has dropped out |
---|
| 500 | of the cluster. TomcatB removes TomcatA from its membership list, and TomcatA will no longer |
---|
| 501 | be notified of any changes that occurs in TomcatB. |
---|
| 502 | The load balancer will redirect the requests from TomcatA to TomcatB and all the sessions |
---|
| 503 | are current. |
---|
| 504 | </p><p></p> |
---|
| 505 | </li> |
---|
| 506 | <li><b><code>TomcatB</code> receives a request for session <code>S1</code></b> |
---|
| 507 | <p>Nothing exciting, TomcatB will process the request as any other request. |
---|
| 508 | </p><p></p> |
---|
| 509 | </li> |
---|
| 510 | <li><b><code>TomcatA</code> starts up</b> |
---|
| 511 | <p>Upon start up, before TomcatA starts taking new request and making itself |
---|
| 512 | available to it will follow the start up sequence described above 1) 2). |
---|
| 513 | It will join the cluster, contact TomcatB for the current state of all the sessions. |
---|
| 514 | And once it receives the session state, it finishes loading and opens its HTTP/mod_jk ports. |
---|
| 515 | So no requests will make it to TomcatA until it has received the session state from TomcatB. |
---|
| 516 | </p><p></p> |
---|
| 517 | </li> |
---|
| 518 | <li><b><code>TomcatA</code> receives a request, invalidate is called on the session (<code>S1</code>)</b> |
---|
| 519 | <p>The invalidate is call is intercepted, and the session is queued with invalidated sessions. |
---|
| 520 | When the request is complete, instead of sending out the session that has changed, it sends out |
---|
| 521 | an "expire" message to TomcatB and TomcatB will invalidate the session as well. |
---|
| 522 | </p><p></p> |
---|
| 523 | |
---|
| 524 | </li> |
---|
| 525 | <li><b><code>TomcatB</code> receives a request, for a new session (<code>S2</code>)</b> |
---|
| 526 | <p>Same scenario as in step 3) |
---|
| 527 | </p><p></p> |
---|
| 528 | |
---|
| 529 | |
---|
| 530 | </li> |
---|
| 531 | <li><code>TomcatA</code> The session <code>S2</code> expires due to inactivity. |
---|
| 532 | <p>The invalidate is call is intercepted the same was as when a session is invalidated by the user, |
---|
| 533 | and the session is queued with invalidated sessions. |
---|
| 534 | At this point, the invalidet session will not be replicated across until |
---|
| 535 | another request comes through the system and checks the invalid queue. |
---|
| 536 | </p><p></p> |
---|
| 537 | </li> |
---|
| 538 | </ol> |
---|
| 539 | |
---|
| 540 | <p>Phuuuhh! :)</p> |
---|
| 541 | |
---|
| 542 | <p><b>Membership</b> |
---|
| 543 | Clustering membership is established using very simple multicast pings. |
---|
| 544 | Each Tomcat instance will periodically send out a multicast ping, |
---|
| 545 | in the ping message the instance will broad cast its IP and TCP listen port |
---|
| 546 | for replication. |
---|
| 547 | If an instance has not received such a ping within a given timeframe, the |
---|
| 548 | member is considered dead. Very simple, and very effective! |
---|
| 549 | Of course, you need to enable multicasting on your system. |
---|
| 550 | </p> |
---|
| 551 | |
---|
| 552 | <p><b>TCP Replication</b> |
---|
| 553 | Once a multicast ping has been received, the member is added to the cluster |
---|
| 554 | Upon the next replication request, the sending instance will use the host and |
---|
| 555 | port info and establish a TCP socket. Using this socket it sends over the serialized data. |
---|
| 556 | The reason I choose TCP sockets is because it has built in flow control and guaranteed delivery. |
---|
| 557 | So I know, when I send some data, it will make it there :) |
---|
| 558 | </p> |
---|
| 559 | |
---|
| 560 | <p><b>Distributed locking and pages using frames</b> |
---|
| 561 | Tomcat does not keep session instances in sync across the cluster. |
---|
| 562 | The implementation of such logic would be to much overhead and cause all |
---|
| 563 | kinds of problems. If your client accesses the same session |
---|
| 564 | simultanously using multiple requests, then the last request |
---|
| 565 | will override the other sessions in the cluster. |
---|
| 566 | </p> |
---|
| 567 | |
---|
| 568 | </blockquote></td></tr></table><table cellpadding="2" cellspacing="0" border="0"><tr><td bgcolor="#525D76"><font face="arial,helvetica.sanserif" color="#ffffff"><a name="Monitoring your Cluster with JMX"><strong>Monitoring your Cluster with JMX</strong></a></font></td></tr><tr><td><blockquote> |
---|
| 569 | <p>Monitoring is a very important question when you use a cluster. Some of the cluster objects are JMX MBeans </p> |
---|
| 570 | <p>Add the following parameter to your startup script with Java 5: |
---|
| 571 | <div align="left"><table border="0" cellpadding="0" cellspacing="4"><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#ffffff"><pre> |
---|
| 572 | set CATALINA_OPTS=\ |
---|
| 573 | -Dcom.sun.management.jmxremote \ |
---|
| 574 | -Dcom.sun.management.jmxremote.port=%my.jmx.port% \ |
---|
| 575 | -Dcom.sun.management.jmxremote.ssl=false \ |
---|
| 576 | -Dcom.sun.management.jmxremote.authenticate=false |
---|
| 577 | </pre></td><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr></table></div> |
---|
| 578 | </p> |
---|
| 579 | <p>Activate JMX with JDK 1.4: |
---|
| 580 | <ol> |
---|
| 581 | <li>Install the compat package</li> |
---|
| 582 | <li>Install the mx4j-tools.jar at common/lib (use the same mx4j version as your tomcat release)</li> |
---|
| 583 | <li>Configure a MX4J JMX HTTP Adaptor at your AJP Connector<p></p> |
---|
| 584 | <div align="left"><table border="0" cellpadding="0" cellspacing="4"><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#ffffff"><pre> |
---|
| 585 | <Connector port="${AJP.PORT}" |
---|
| 586 | handler.list="mx" |
---|
| 587 | mx.enabled="true" |
---|
| 588 | mx.httpHost="${JMX.HOST}" |
---|
| 589 | mx.httpPort="${JMX.PORT}" |
---|
| 590 | protocol="AJP/1.3" /> |
---|
| 591 | </pre></td><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr></table></div> |
---|
| 592 | </li> |
---|
| 593 | <li>Start your tomcat and look with your browser to http://${JMX.HOST}:${JMX.PORT}</li> |
---|
| 594 | <li>With the connector parameter <code>mx.authMode="basic" mx.authUser="tomcat" mx.authPassword="strange"</code> you can control the access!</li> |
---|
| 595 | </ol> |
---|
| 596 | </p> |
---|
| 597 | <p> |
---|
| 598 | List of Cluster Mbeans<br> |
---|
| 599 | <table border="1" cellpadding="5"> |
---|
| 600 | |
---|
| 601 | <tr> |
---|
| 602 | <th align="center" bgcolor="aqua">Name</th> |
---|
| 603 | <th align="center" bgcolor="aqua">Description</th> |
---|
| 604 | <th align="center" bgcolor="aqua">MBean ObjectName - Engine</th> |
---|
| 605 | <th align="center" bgcolor="aqua">MBean ObjectName - Host</th> |
---|
| 606 | </tr> |
---|
| 607 | |
---|
| 608 | <tr> |
---|
| 609 | <td>Cluster</td> |
---|
| 610 | <td>The complete cluster element</td> |
---|
| 611 | <td><code>type=Cluster</code></td> |
---|
| 612 | <td><code>type=Cluster,host=${HOST}</code></td> |
---|
| 613 | </tr> |
---|
| 614 | |
---|
| 615 | <tr> |
---|
| 616 | <td>DeltaManager</td> |
---|
| 617 | <td>This manager control the sessions and handle session replication </td> |
---|
| 618 | <td><code>type=Manager,path=${APP.CONTEXT.PATH}, host=${HOST}</code></td> |
---|
| 619 | <td><code>type=Manager,path=${APP.CONTEXT.PATH}, host=${HOST}</code></td> |
---|
| 620 | </tr> |
---|
| 621 | |
---|
| 622 | <tr> |
---|
| 623 | <td>ReplicationValve</td> |
---|
| 624 | <td>This valve control the replication to the backup nodes</td> |
---|
| 625 | <td><code>type=Valve,name=ReplicationValve</code></td> |
---|
| 626 | <td><code>type=Valve,name=ReplicationValve,host=${HOST}</code></td> |
---|
| 627 | </tr> |
---|
| 628 | |
---|
| 629 | <tr> |
---|
| 630 | <td>JvmRouteBinderValve</td> |
---|
| 631 | <td>This is a cluster fallback valve to change the Session ID to the current tomcat jvmroute.</td> |
---|
| 632 | <td><code>type=Valve,name=JvmRouteBinderValve, |
---|
| 633 | path=${APP.CONTEXT.PATH}</code></td> |
---|
| 634 | <td><code>type=Valve,name=JvmRouteBinderValve,host=${HOST}, |
---|
| 635 | path=${APP.CONTEXT.PATH}</code></td> |
---|
| 636 | </tr> |
---|
| 637 | |
---|
| 638 | </table> |
---|
| 639 | </p> |
---|
| 640 | </blockquote></td></tr></table><table cellpadding="2" cellspacing="0" border="0"><tr><td bgcolor="#525D76"><font face="arial,helvetica.sanserif" color="#ffffff"><a name="FAQ"><strong>FAQ</strong></a></font></td></tr><tr><td><blockquote> |
---|
| 641 | <p>Please see <a href="http://tomcat.apache.org/faq/cluster.html">the clustering section of the FAQ</a>.</p> |
---|
| 642 | </blockquote></td></tr></table></td></tr><!--FOOTER SEPARATOR--><tr><td colspan="2"><hr size="1" noshade></td></tr><!--PAGE FOOTER--><tr><td colspan="2"><div align="center"><font size="-1" color="#525D76"><em> |
---|
| 643 | Copyright © 1999-2008, Apache Software Foundation |
---|
| 644 | </em></font></div></td></tr></table></body></html> |
---|