Apache Tomcat, the open source Web application server, hosts an estimated 70 percent of small Java Web applications. However Tomcat can become overburdened when faced with spikes in user requests. One way to ensure that your Tomcat servers are utilized to their maximum capacity is to connect and cluster them in a single environment and then load balance the servers in that environment. The mod_cluster module enables you to do just that: connect multiple servers and perform load balancing. Using mod_cluster, you can use a single IP address to connect multiple deployed Web servers.
Load balancing is basically defined as connectivity with one or more Web application servers for handling increasing user loads. Apart from checking the connected server load, load balancing also helps to route user requests to free servers, thereby lessening the burden on loaded servers. The two supported cluster modes are single-cluster mode and dynamic-cluster mode, with single-cluster mode being the default. In single-cluster mode, all server machines are used even when very few users access the Web application, which is a waste of network, power and server resources. If the number of users increases, then the response of the application will go down, because fewer servers are used to serve the request.
By setting up a dynamic Tomcat cluster environment where you can add or remove servers dynamically based on the user load, you can implement a sort of Tomcat platform as a service (PaaS) that ably addresses the problem of resource utilization. The following figure illustrates the Tomcat PaaS architecture.
This solution will improve resource utilization while load balancing the environment. In this tutorial, we explain how to implement a dynamic Tomcat cluster with mod_cluster.
The Case for Mod_cluster
Mod_cluster is an httpd-based load balancer that uses a communication channel to forward requests from httpd to a set of application server nodes. Unlike mod_jk and mod_proxy, mod_cluster utilizes an additional connection between the application server nodes and httpd. The application server nodes use this connection to send server-side load balance factors and lifecycle events back to httpd via the Mod-Cluster Management Protocol (MCMP), a custom set of HTTP methods. With this additional feedback channel, mod_cluster can provide more intelligence and granularity than many other load-balancing alternatives, as well as the following advantages.
- Dynamic configuration of httpd workers
- Server-side load balance factor calculation
- Fine-grained Web app lifecycle control
- AJP is optional