This tutorial is about Load Balancing a cluster of WildFly servers using a WildFly Web server configured using the load balancer profile.

Since WildFly 9, you can use an instance of the Application Server as a mod_cluster front-end for your back-end applications. This will remove the need to use a native Web server like Apache (and mod_cluster libs installed on it) as load balancer to a cluster of WildFly servers.

Here is a sample view of a cluster of WildFly backend servers fronted by a WildFly frontend server configured to route request using the Mod_cluster Management Protocol (MCMP):

wildfly load balancing tutorial jboss load balancing

Configuring the Load Balancer Back end

Back end servers obviously require that an ha or full-ha profile for your cluster to work.

Besides it, make sure that you are deploying a cluster-aware application on the top of WildFly. That is, an application which includes in the web.xml file

<distributable />

Configuring the Load Balancer Front end

WildFly includes in its domain.xml configuration a server profile named "load-balancer" which is a minimal server configuration featuring an Undertow Web server. This configuration, as you can

see from the following snippet, is used to filter the incoming traffic to your cluster of application servers through mod-cluster:

<subsystem xmlns="urn:jboss:domain:undertow:9.0" default-server="default-server" default-virtual-host="default-host" default-servlet-container="default" statistics-enabled="${wildfly.undertow.statistics-enabled:${wildfly.statistics-enabled:false}}">
    <buffer-cache name="default"/>
    <server name="default-server">
        <http-listener name="default" socket-binding="http" redirect-socket="https" enable-http2="true"/>
        <http-listener name="management" socket-binding="mcmp-management" enable-http2="true"/>
        <host name="default-host" alias="localhost">
            <filter-ref name="load-balancer"/>
        </host>
    </server>
    <servlet-container name="default"/>
    <filters>
        <mod-cluster name="load-balancer" management-socket-binding="mcmp-management" advertise-socket-binding="modcluster" enable-http2="true" max-retries="3"/>
    </filters>
</subsystem>

The Undertow’s filter is used to balance the incoming requests through the advertising mechanism of modcluster.

A sample standalone configuration named standalone-load-balancer.xml is also available as template for standalone servers.

Manually configuring the Undertow filter

If you are using a version prior to WildFly 10.1, you will need to manually add the Undertow filter, which will use mod_cluster’s advertise ports (port=23364, multicast-address=224.0.1.105). Here is the batch script we will need to execute on the WildFly front end CLI:

batch
/subsystem=undertow/configuration=filter/mod-cluster=modcluster:add(management-socket-
binding=http,advertise-socket-binding=modcluster)
/subsystem=undertow/server=default-server/host=default-host/filter-ref=modcluster:add
# The following is needed only if you are not running an ha profile !**
/socket-binding-group=standard-sockets/socket-binding=modcluster:add(port=23364,
multicast-address=224.0.1.105)
run-batch

Now reload your configuration for the changes to take effect.

[standalone@localhost:9990/] reload

As a result, the modcluster filter has been added to the default-host server. Congratulations! You have just configured a WildFly server to act as Load Balancer!

0
0
0
s2sdefault

Related articles available on mastertheboss.com

JBoss Clustering a Web Application

Please Note: This article cover JBoss AS 4/5/6 releases. If you w

Clustering EJB 3 with JBoss AS

To cluster a stateless session bean in EJB 3 all you need to do i

JBoss monitoring HTTP Session replication

In this article we'll show how to monitor HTTPSession replication

How do I change multicast address of JBoss cluster ?

Since JBoss AS 4.0.3, the jboss.partition.udpGroup property can b

JBoss farming service

What is the farming service ? this article explains about it, als

JBoss HTTP Session replication

HTTP session replication is used to replicate the state associate