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.

Portrait of Matt Ryall

About Matt

I’m a technology nerd, husband and father of four, living in beautiful Sydney, Australia.

My passion is building software products that make the world a better place. For the last 15 years, I’ve led product teams at Atlassian to create collaboration tools.

I'm also a startup advisor and investor, with an interest in advancing the Australian space industry. You can read more about my work on my LinkedIn profile.

To contact me, please send an email or reply on Twitter.