Skip to end of metadata
Go to start of metadata

Wildfly 9 adds support for using the Undertow subsystem as a load balancer. Wildfly supports two different approaches, you can either define a static load balancer, and specify the back end hosts in your configuration, or use it as a mod_cluster frontend, and use mod_cluster to dynamically update the hosts.

General Overview

Wildfly uses Undertow's proxy capabilities to act as a load balancer. Undertow will connect to the back end servers using its built in client, and proxies requests.

The following protocols are supported:

  • http
  • ajp
  • http2
  • h2c (clear text HTTP2)
    Of these protocols h2c should give the best performance, if the back end servers support it.

The Undertow proxy uses async IO, the only threads that are involved in the request is the IO thread that is responsible for the connection. The connection to the back end server is made from the same thread, which removes the need for any thread safety constructs.
If both the front and back end servers support server push, and HTTP2 is in use then the proxy also supports pushing responses to the client. In cases where proxy and backend are capable of server push, but the client does not support it the server will send a X-Disable-Push header to let the backend know that it should not attempt to push for this request.

Using Wildfly as a static load balancer

To use Wildfly as a static load balancer the first step is to create a proxy handler in the Undertow subsystem. For the purposes of this example we are going to assume that our load balancer is going to load balance between two servers, sv1.foo.com and sv2.foo.com, and will be using the AJP protocol.

The first step is to add a reverse proxy handler to the Undertow subsystem:

Then we need to define outbound socket bindings for remote hosts

and than we add them as hosts to reverse proxy handler

Now we need to actually add the reverse proxy to a location. I am going to assume we are serving the path /app:

This is all there is to it. If you point your browser to http://localhost:8080/app you should be able to see the proxied content.

The full details of all configuration options available can be found in the subsystem reference.

Labels:
None
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
  1. Nov 19, 2015

    Is this content still valid for WildFly10? If yes, could you copy over to WIldFly 10 ?

  2. Feb 09, 2016

    Following command is not working:

    /subsystem=undertow/configuration=handler/reverse-proxy=my-handler/host=ajp://sv1.foo.com::add()

    Ref: https://developer.jboss.org/thread/262561?start=0&tstart=0

    1. Feb 09, 2016

      Even after replacing :: with :, I am getting error

      [standalone@localhost:9990 /] /subsystem=undertow/configuration=handler/reverse-
      proxy=my-handler/host=ajp://sv1.foo.com:add()
      '//sv1.foo.com:add' is not a valid operation name.
      [standalone@localhost:9990 /] /subsystem=undertow/configuration=handler/reverse-proxy=my-handler/host=ajp://sv1.foo.com:add()

      '//sv1.foo.com:add' is not a valid operation name.

  3. Jan 25, 2017

    Greate...working like a champ :)