Loading Balancing a JEE application using Tomcat and mod_cluster
Performance, scalability, and reliability are key factors to many production applications. Designing and implementing a highly performant, scalable, and reliable application is not an easy task. Furthermore, a single piece of computing hardware may not suffice in terms of the resources necessary to run and scale your application. As your user base grows, and continues to grow, your application will likely require more and more resources. In these cases, it is often useful to consider load balancing options. A load balancer can be used to distribute the workload across multiple systems. Some load balancers are also capable of seamlessly adding and removing systems from a cluster as resource requirements rise and fall. mod_cluster is a JBoss project that provides both capabilities for JEE applications. mod_cluster also supports the Apache HTTP server and the Apache Tomcat and JBoss Java application servers.
In this post, we will provide a brief overview of clustering and load balancing. We will also describe what makes the mod_cluster load balancer stand out with respect to other open source alternatives. Finally, we will describe how to set up and configure mod_cluster.
What is Clustering?
- At a high level, clustering is a set of computers that work together and appear to operate as a single machine.
It beneficial for a cluster to accept and remove nodes without incurring downtime. (mod_cluster provides this capability). What is a node? ? Here a node is a single computer in the cluster.
What is load balancing?
- Load balancing is a method used to distribute a workload across a cluster of computer systems and provides a means to better optimize resource usage, increase throughput, and improve thesystem’s reliability through redundancy.
mod_cluster is an HTTP based load balancer that can be used as a module within an Apache HTTP Server. mod_cluster creates a connection between cluster nodes and the HTTP server and each that each cluster node uses to transmit load factors and lifecycle events back to the HTTP server. Based on this information, the HTTP server using mod_cluster intelligently distributes load across its cluster nodes.
The intelligence of mod_cluster is its most notable characteristic. It is far more intelligent than mod_balancer which is typically used with Apache HTTP server. It’s configuration largely resides on the HTTP server. Because of this, it is fairly dumb in terms of how it distributes load. Load distribution is handled by normalizing the number of requests or bytes sent to each machine.
mod_cluster, on the other hand, is far more intelligent and unique in that, much of the configuration resides in the cluster nodes, not on the HTTP server. Cluster nodes register themselves with the HTTP Server, thus making it very easy to add and remove nodes from the cluster without incurring downtime. Also, load_factors are calculated by the cluster node, not the HTTP server! The cluster node can supply far better load information about itself, and thus enables the HTTP server to make much better decisions.
Are you sold on the benefits of mod_cluster? If so, here’s how you set it up.
mod_cluster provides two sets of binaries. The HTTP Server binaries and the application server (or cluster node binaries)
1. Install/Config mod_cluster on the HTTP Server
This quick start guide sections 2.1-2.3 as its provides comprehensive instructions.
2. Install mod_cluster on a Tomcat cluster node
cp -r /tmp/mod-cluster/JBossWeb-Tomcat/lib/* $CATALINA_HOME/lib/
See section 2.4
3. Configure server.xml
Add the following directive to server.xml
<Listener className="org.jboss.modcluster.container.catalina.standalone.ModClusterListener" advertise="true"/>
4. Start HTTP and each cluster node
cd $CATALINA_HOME ./startup.sh
For JBoss instructions, see here.