Using JDG as External Cache Container for WildFly HTTP Session Replication: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
No edit summary
 
(21 intermediate revisions by the same user not shown)
Line 6: Line 6:


* [[WildFly Infinispan HTTP Session Replication Configuration#Subjects|WildFly Infinispan HTTP Session Replication Configuration]]
* [[WildFly Infinispan HTTP Session Replication Configuration#Subjects|WildFly Infinispan HTTP Session Replication Configuration]]
=Relevance=
* EAP 6.5, JDG 6.6
{{Error|02/08/17 This article is obsolete, update it with the content of "c100/doc/... 2016.09.13 - V3 - JDG Implementation Recommendations.docx"}}


=Overview=
=Overview=
Line 13: Line 20:
=Setup the JDG Cluster=
=Setup the JDG Cluster=


Configuration details are available here: [[Infinispan Configuration]]. The external JDG cluster will be accessed by the WildFly instance over the HotRod protocol.
The JDG cluster is essentially an Infinispan cluster and details on how to set up the cluster are available here:
 
<blockquote style="background-color: #f9f9f9; border: solid thin lightgrey;">
:[[Infinispan Configuration]]
</blockquote>
 
The external JDG clustert thus configured will be accessed by the WildFly instance over the HotRod protocol.
 
A JDG cluster is capable of managing multiple cache instances. In case the JDG cluster is deployed with the only purpose of storing HTTP session state for one (or more) web applications, it is recommended to remove any other cache container (except “security") and the corresponding cache declaration, even those provided as example in the default configuration file, and only maintain a single cache container that manages a cache instance per web application. The example below assumes a single web application, and implicitly, and a single cache. The suggested name for the cache is “http-session-cache”.
 
<blockquote style="background-color: Gold; border: solid thin Goldenrod;">
:Each web application will require a dedicated cache.<br>
</blockquote>


Define a dedicated cache for each web application:
The relevant cache configuration is located in the “infinispan:server:core” subsystem:


<pre>
<pre>
<subsystem xmlns="urn:infinispan:server:core:6.4">
<subsystem xmlns="urn:infinispan:server:core:6.4" default-cache-container="clustered">
   <cache-container name="clustered" default-cache="default" statistics="true">
   <cache-container name="clustered" default-cache="http-session-cache" statistics="true">
     <transport executor="infinispan-transport" lock-timeout="60000"/>
     <transport executor="infinispan-transport" lock-timeout="60000"/>
     <distributed-cache name="default" ...>
     <distributed-cache name="http-session-cache" mode="SYNC" segments="20" owners="2" remote-timeout="30000" start="EAGER"/>
      ...
    </distributed-cache>
    <distributed-cache name="http-sessions" owners="2" mode="SYNC" start="EAGER"/>
   </cache-container>
   </cache-container>
   ...
   <cache-container name="security"/>
</subsystem>
</subsystem>
</pre>
=Configure the WildFly Cache=
For each distributable application, an entirely new WildFly cache must be created.
The first one can be created reconfiguring the existing 'web cache container. All other cache containers/caches can be removed.
<pre>
        <subsystem xmlns="urn:jboss:domain:infinispan:1.5">
            <cache-container name="web" aliases="standard-session-cache" default-cache="repl" module="org.jboss.as.clustering.web.infinispan">
                <transport lock-timeout="60000"/>
                <replicated-cache name="repl" mode="ASYNC" batching="true">
                    <remote-store cache="http-session-cache" socket-timeout="60000" tcp-no-delay="true" shared="true" preload="false" passivation="false" fetch-state="false" purge="false">
                        <remote-server outbound-socket-binding="initial-jdg-server"/>
                    </remote-store>
                </replicated-cache>
            </cache-container>
        </subsystem>
</pre>
==Remote Cache <tt>preload</tt> Setting==
The <tt>preload</tt> setting should be <tt>false</tt>, because If the store is configured to preload the cache, when the cache starts all data stored in the store will be pre-loaded into memory, This is rarely what we want. Clustered HTTP caches are usually large, exceeding the capacity of heap, and there's no point in loading all the HTTP sessions from the distributed cache into the memory of a node, anyway.
For more details on preload, see [[Infinispan_Concepts#Cache_Store_Preloading|Cache Store Preloading]].
==Startup Options==
The JDG-backed infinispan cache starts lazily with the default configuration. That mean it will only connect to the JDG cluster when a distributable web application is deployed. Sometimes might be desirable to start the cache and connect to the JDG server as soon as the WildFly server boots. To achieve that, configure the cache to start "EAGER":
<pre>
    ...
    <replicated-cache name="repl" mode="ASYNC" batching="true" start="EAGER">
        ...
    </replicated-cache>
    ...
</pre>
=Declare the Outbound Socket=


<pre>
    <socket-binding-group name="standard-sockets" default-interface="public" port-offset="${jboss.socket.binding.port-offset:0}">
        ...
        <outbound-socket-binding name="initial-jdg-server">
            <remote-destination host="localhost" port="11222"/>
        </outbound-socket-binding>
    </socket-binding-group>
</pre>
</pre>
=Configura the Application to be Distributable=
See:
<blockquote style="background-color: #f9f9f9; border: solid thin lightgrey;">
:[[HTTP Session Replication]]
</blockquote>

Latest revision as of 20:38, 8 February 2017

External

Internal

Relevance

  • EAP 6.5, JDG 6.6



02/08/17 This article is obsolete, update it with the content of "c100/doc/... 2016.09.13 - V3 - JDG Implementation Recommendations.docx"

Overview

JDG can be used as an external cache container for HTTP session data within WildFly. This allows scaling of the data layer independent of the application, and enables different WildFly clusters, that may reside in various domains, to access data from the same JDG cluster.

Setup the JDG Cluster

The JDG cluster is essentially an Infinispan cluster and details on how to set up the cluster are available here:

Infinispan Configuration

The external JDG clustert thus configured will be accessed by the WildFly instance over the HotRod protocol.

A JDG cluster is capable of managing multiple cache instances. In case the JDG cluster is deployed with the only purpose of storing HTTP session state for one (or more) web applications, it is recommended to remove any other cache container (except “security") and the corresponding cache declaration, even those provided as example in the default configuration file, and only maintain a single cache container that manages a cache instance per web application. The example below assumes a single web application, and implicitly, and a single cache. The suggested name for the cache is “http-session-cache”.

Each web application will require a dedicated cache.

The relevant cache configuration is located in the “infinispan:server:core” subsystem:

<subsystem xmlns="urn:infinispan:server:core:6.4" default-cache-container="clustered">
  <cache-container name="clustered" default-cache="http-session-cache" statistics="true">
    <transport executor="infinispan-transport" lock-timeout="60000"/>
    <distributed-cache name="http-session-cache" mode="SYNC" segments="20" owners="2" remote-timeout="30000" start="EAGER"/>
  </cache-container>
  <cache-container name="security"/>
</subsystem>

Configure the WildFly Cache

For each distributable application, an entirely new WildFly cache must be created.

The first one can be created reconfiguring the existing 'web cache container. All other cache containers/caches can be removed.

        <subsystem xmlns="urn:jboss:domain:infinispan:1.5">
            <cache-container name="web" aliases="standard-session-cache" default-cache="repl" module="org.jboss.as.clustering.web.infinispan">
                <transport lock-timeout="60000"/>
                <replicated-cache name="repl" mode="ASYNC" batching="true">
                    <remote-store cache="http-session-cache" socket-timeout="60000" tcp-no-delay="true" shared="true" preload="false" passivation="false" fetch-state="false" purge="false">
                        <remote-server outbound-socket-binding="initial-jdg-server"/>
                    </remote-store>
                </replicated-cache>
            </cache-container>
        </subsystem>

Remote Cache preload Setting

The preload setting should be false, because If the store is configured to preload the cache, when the cache starts all data stored in the store will be pre-loaded into memory, This is rarely what we want. Clustered HTTP caches are usually large, exceeding the capacity of heap, and there's no point in loading all the HTTP sessions from the distributed cache into the memory of a node, anyway.

For more details on preload, see Cache Store Preloading.

Startup Options

The JDG-backed infinispan cache starts lazily with the default configuration. That mean it will only connect to the JDG cluster when a distributable web application is deployed. Sometimes might be desirable to start the cache and connect to the JDG server as soon as the WildFly server boots. To achieve that, configure the cache to start "EAGER":

    ...
    <replicated-cache name="repl" mode="ASYNC" batching="true" start="EAGER">
        ... 
    </replicated-cache>
    ...

Declare the Outbound Socket

    <socket-binding-group name="standard-sockets" default-interface="public" port-offset="${jboss.socket.binding.port-offset:0}">
        ...
        <outbound-socket-binding name="initial-jdg-server">
            <remote-destination host="localhost" port="11222"/>
        </outbound-socket-binding>
    </socket-binding-group>

Configura the Application to be Distributable

See:

HTTP Session Replication