12 April 2006

Load balancing with Tomcat and mod_jk

Perhaps it reflects my lack of understanding of the AJP protocol, but I don't think the mod_jk documentation emphasises this enough:

When using load balancing with mod_jk, the node's worker name must match the jvmRoute attribute of the Tomcat engine in server.xml.

For example, if your workers.properties has a line like this:

worker.loadbalancer.balance_workers=tomcat1,tomcat2

Then your Tomcat server.xml for the first node must have the 'tomcat1' as its jvmRoute value:

<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat1">

Similarly, your second node should have a jvmRoute value of 'tomcat2'.

If you don't do this, session affinity does not work, and you get every request routed to a different node. Therefore load balancing with mod_jk does not work unless you set the jvmRoute value correctly for all nodes.