Advertise with us

Our eBooks

Sticky session configuration in WildFly

Sticky session is a mechanism by which Requests involving session-oriented Servlets/JSP are directed to the the same application instance in the pool for efficiency of processing. In this tutorial we will check how sticky sessions work with WildFly application server.

First of all, where sticky session is configured ? If you are using mod_cluster to manage your cluster, you can check it into the mod_cluster subsystem as follows:

/subsystem=modcluster/proxy=default:read-resource(include-runtime=true)
{
    "outcome" => "success",
    "result" => {
     . . . .
        "sticky-session" => true,
        "sticky-session-force" => false,
        "sticky-session-remove" => false,
        "stop-context-timeout" => 10,
        "ttl" => -1,
        "worker-timeout" => -1,
        "dynamic-load-provider" => {"configuration" => undefined},
        "load-provider" => {"dynamic" => undefined},
        "ssl" => undefined
    }
}

Now let's see in practice how it works.Assumed you have set up a cluster of WildFly application servers, we will now run a two node clusters, using mod_cluster in front of it:

jboss as 7 clustering sticky session mod_cluster

Let's try running a sample Servlet which dumps some logs on the node where it's being executed:

jboss eap tutorial install
As you can see, our quintessential JSP (which dumps the sessionid), is running on the same server node between each request.
Now let's test set to false the sticky-session attribute as follows:

/subsystem=modcluster/proxy=default:write-attribute(name=sticky-session,value=false)

 As you can see, with sticky-session="false", each request is balanced across the cluster and, using the default session replication to keep data in synch between nodes.

jboss eap tutorial install

Besides it, it's worth to notice the other the value of the other attributes included in the mod_cluster's proxy element:

  • sticky-session-force: Indicates whether the reverse proxy should run an error in the event that the balancer is unable to route a request to the node to which it is stuck.
  • sticky-session-remove: Indicates whether the reverse proxy should remove session stickiness in the event that the balancer is unable to route a request to the node to which it is stuck. 

Important! Since WildFly 18 it's possible to use the ranked load balancing mechanism. You can read more here: Configuring Ranked Load Balancing in WildFly

© 2021 mastertheboss.com. All Rights Reserved.

Please publish modules in offcanvas position.