Java Reference
In-Depth Information
Load balancing your web applications
You have several choices available in order to achieve load balancing of your HTTP re-
quests. You can opt for a hardware load balancer that sits in front of your cluster of servers
or you can choose from the many available software solutions for WildFly, which include
the following:
• Use Apache Tomcat's
mod_jk
module to route your requests to your nodes
• Use Apache
mod_proxy
that configures Apache to act as a proxy server and for-
wards requests to WildFly nodes
• Use WildFly's built-in solution
mod_cluster
to achieve dynamic load balancing
of your requests
Here, we will illustrate how to get started with
mod_cluster
—a module for the Apache
HTTP server. The advantage of using
mod_cluster
against other options can be sum-
marized in the following key points:
• Dynamic clustering configuration
• Server-side pluggable load metrics
• Life cycle notifications of the application status
As a matter of fact, when using a standard load balancer such as
mod_jk
, you have to
provide a static list of nodes that is used to spread the load. This is a very limiting factor,
especially if you have to deliver upgrades to your configuration by adding or removing
nodes; alternatively, you simply need to upgrade software used by single nodes. Besides
this, using a flat cluster configuration can be tedious and it is prone to errors, especially if
the number of cluster nodes is high.
When using
mod_cluster
, you can dynamically add or remove nodes from your cluster
because cluster nodes are discovered through an advertising mechanism.
In practice, the
mod_cluster
libraries on the HTTP side send UDP messages on a mul-
ticast group, which is subscribed by WildFly nodes. This allows WildFly nodes to automat-
ically discover HTTP proxies when application life cycle notifications are sent.
The next diagram illustrates this concept better: