Session Replication in Wildfly 10


Pre-Requisites:
  1. If using domain mode, the slave node should belong to the group of full-ha profiles and the master should be configured with the ha or full-ha profile.
  2. Ensure all nodes can communicate with each other in the network
  3. All session attributes must be Serialized


Session replication can be done in two ways Distributed which are by default limited to two nodes and the other is Replication.

 

DISTRIBUTED CACHING


To enable Session Replication need to perform below changes 
  1. In the web application , Add <distributable /> tag in web.xml (this will enable Web session clustering)
  2. Open domain.xml (located at {Wildfly-Home/domain/configuration/})

    3. Search below tag 
    <subsystem xmlns="urn:jboss:domain:messaging-activemq:1.0">

    4. Change cluster password in domain.xml

    <cluster password="${jboss.messaging.cluster.password:CHANGE ME!!}"/>

Search CHANGE ME!! and replace it with an appropriate password.
E.g.

<subsystem xmlns="urn:jboss:domain:messaging-activemq:1.0">

<server name="default">
                <cluster password="${jboss.messaging.cluster.password:A123456.}"/>
........................

      </server>

</subsystem>



Note :
  1. All the objects set in the HttpSession should be Serialized for Session Replication
  2. Session Replication is done by default to only 2 nodes and it is distributed caching
  3. To replicate it to all nodes need to change it to a replicated cache

REPLICATED CACHING 


To enable replicated caching to all nodes in the cluster

1. Open domain.xml (Path : Wildfly-home/domain/configuration)
Now search for below tag
<subsystem xmlns="urn:jboss:domain:infinispan:4.0">

2. Replace below tag 


<cache-container name="web" default-cache="dist" module="org.wildfly.clustering.web.infinispan">
   <transport lock-timeout="60000" />
   <distributed-cache name="dist" mode="ASYNC" l1-lifespan="0" owners="2">
      <locking isolation="REPEATABLE_READ" />
      <transaction mode="BATCH" />
      <file-store />
   </distributed-cache>
   <distributed-cache name="concurrent" mode="SYNC" l1-lifespan="0" owners="2">
      <file-store />
   </distributed-cache>
</cache-container>

 

With 

 


<cache-container name="web" default-cache="repl" module="org.wildfly.clustering.web.infinispan">
   <transport lock-timeout="60000" />
   <replicated-cache name="repl" mode="ASYNC">
      <transaction locking="OPTIMISTIC" />
      <transaction mode="BATCH" />
      <locking isolation="READ_COMMITTED" />
      <file-store />
   </replicated-cache>
</cache-container>
 
 

OPTIMISTIC locking with an isolation level of READ_COMMITTED allows serving concurrent requests within the same HTTP session while also supporting failover.

By default, Wildfly configures distributed and replicated Infinispan caches to use PESSIMISTIC locking with REPEATABLE_READ isolation, which causes reads from the session cache to block other read attempts. That is why we changed it to OPTIMISTIC locking.

Comments

Popular Posts