Apache TomcatApache Logo

The Apache Tomcat Connector - Generic HowTo

LoadBalancer HowTo


A Load balancer is a virtual worker that does not really communicate with Tomcat workers. Instead it is responsible for the management of several "real" workers. The worker is supposed to be a load balancer if its worker type is lb. See workers type directive. For a complete reference of all load balancer configuration items, please consult the worker reference. The comprehensive status management features of the load balancer together with the status worker, makes its use an interesting option, even if only combined with a single "real" worker.

The workers that are member of load balancer do not need to appear in the worker.list directive.

lb Worker properties

The load-balancing worker does not really communicate with Tomcat workers. Instead it is responsible for the management of several "real" workers. This management includes:

  • Instantiating the workers in the web server.
  • Using the worker's load-balancing factor, perform weighed-round-robin load balancing where high lbfactor means stronger machine (that is going to handle more requests)
  • Keeping requests belonging to the same session executing on the same Tomcat worker.
  • Identifying failed Tomcat workers, suspending requests to them and instead falling-back on other workers managed by the lb worker.

The overall result is that workers managed by the same lb worker are load-balanced (based on their lbfactor and current user session) and also fall-backed so a single Tomcat process death will not "kill" the entire site.

If you want to use session stickyness, you must set different jvmRoute attributes in the Engine element in Tomcat's server.xml. Furthermore the names of the workers which are managed by the balancer have to be equal to the jvmRoute of the Tomcat instance they connect with.

The following table specifies some properties that the lb worker can accept:

  • balance_workers is a comma separated list of workers that the load balancer need to manage. These workers do not need to appear in the worker.list property. This directive can be used multiple times for the same load balancer.
  • sticky_session specifies whether requests with SESSION ID's should be routed back to the same Tomcat worker. You can set sticky_session to False when Tomcat is using a Session Manager which can persist session data across multiple instances of Tomcat. By default sticky_session is set to True.

  # The worker balance1 while use "real" workers worker1 and worker2
  worker.balance1.balance_workers=worker1, worker2
Advanced lb Worker properties

With JK 1.2.x, new load-balancing and fault-tolerant support has been added via 2 new properties, redirect and activation.

Let's take an example environment:

A cluster with two nodes (worker1+worker2), running a webserver + tomcat tandem on each node and a loadbalancer in front of the nodes.

  # The advanced router LB worker

  # Define a worker using ajp13
  # Define prefered failover node for worker1

  # Define another worker using ajp13
  # Disable worker2 for all requests except failover
  # Define the LB worker

The redirect flag on worker1 tells the lb_worker to redirect the requests to worker2 only if worker1 is in error state. In other cases worker2 will not receive any requests, thus acting like a hot standby.

Status Worker properties

The status worker does not communicate with Tomcat. Instead it is responsible for the load balancer management.

  # Add the status worker to the worker list
  # Define a 'jkstatus' worker using status

Next thing is to mount the requests to the jkstatus worker. For Apache web servers use the:

  # Add the jkstatus mount point
  JkMount /jkmanager/* jkstatus 

To obtain a higher level of security use the:

  # Enable the JK manager access from localhost only
 <Location /jkmanager/>
    JkMount jkstatus
    Order deny,allow
    Deny from all
    Allow from

Copyright © 1999-2005, Apache Software Foundation