Mindmajix

Configuring session cache containers

session data: HTTP Session and Stateful session beans. While the two mechanisms are conceptually different, the way they are implemented, they are quite similar as far as it concerns session synchronization across the cluster. For this reason, we will discuss them in a single section, showing the similarities between them. So, here’s the cache-container configuration for the web cache and the sfsb cache:

<cache-container name=”web” default-cache=”repl”>
<alias>standard-session-cache</alias>
<replicated-cache mode=”ASYNC” name=”repl” batching=”true”>
<locking isolation=”REPEATABLE_READ”/>
<file-store/>
</replicated-cache>
<distributed-cache mode=”ASYNC” name=”dist” batching=”true”>
<locking isolation=”REPEATABLE_READ”/>
<file-store/>

</distributed-cache>
</cache-container>
<cache-container name=”sfsb” default-cache=”repl”>
<alias>sfsb-cache</alias>
<alias>jboss.cache:service=EJB3SFSBClusteredCache
</alias>
<replicated-cache mode=”ASYNC” name=”repl” batching=”true”>
<locking isolation=”REPEATABLE_READ”/>
<eviction strategy=”LRU” max-entries=”10000″/>
<file-store/>
</replicated-cache>
</cache-container>

As you can see, the web cache container configuration can contain one or more caching strategies: the replicated-cache and the distributed-cache , the former being the default one. In the next section, we will explore in detail the differences and the gotchas between these two cache modes. At the moment, bear in mind that if you want to change the clustering mode, all you have to do is adapting the default-cache attribute to your
cache mode.

As far as it is concerned the data synchronization across members can be carried out using either synchronous messages (SYNC) or asynchronous messages (ASYNC).

Synchronous messaging is the least efficient mode as each node will wait for message acknowledgement from all cluster members. However, synchronous mode is needed when all the nodes in the cluster may access the cached data, resulting in a high need for consistency.

Screenshot_40

Asynchronous messaging enhances speed rather than consistency and this is particularly advantageous in use cases such as HTTP session replication with sticky sessions enabled. In these scenarios, a session is always accessed on the same cluster node, and only in case of failure is data accessed in a different node.

Screenshot_41

Inside each cache definition, you should have noticed the locking-isolation element that corresponds in semantic to the equivalent database isolation levels. Infinispan only supports READ_COMMITTED or REPEATABLE_READ isolation level s.

Another element that is included in both caches is file-store, which configures the path in which to store the cached data. The default data is written into the jboss.server.data.dir directory under a directory named as the cache container name. For example, here’s the default file-store path for the standalone web cache container:

Screenshot_42

You can, however, customize the file-store path using the relative-to and path element, just as we showed in past tutorial for the path element:

<file-store relative-to=”…” path=”…”/>
By having a clear idea of the elements, which include a part of the configuration, we want to hammer on the differences between replicated and distributed caches, without which, you will miss the whole picture.

Choosing between replication and distribution When using a replication, cache Infinispan will store every entry on every node in the cluster grid. This means that entries added to any of these cache instances will be replicated to all other cache instances in the cluster, and can be retrieved from any instance locally.

Screenshot_43

Screenshot_44

The scalability of replication is a function of cluster size and average data size, so if we have many nodes and/or large data sets, then we hit a scalability ceiling.

On the other hand, when using distributed caching, Infinispan will store every cluster entry on a subset of the nodes in the grid thereby allowing to scale linearly as more servers are added to the cluster.

Distribution makes use of a consistent hash algorithm to determine where in a cluster entries should be stored. Hashing algorithm is configured with the number of copies each cache entry should be maintained cluster-wide. The number of copies represents the trade-off between performance and durability of data. The more copies you
maintain, the lower performance will be, but also the lower the risk of losing data due to server outages.

You can use the owners parameter (default 2) to define the number of cluster-wide replicas for each cache entry.
<distributed-cache owners=”3″ mode=”ASYNC” name=”dist”
batching=”true”>
. . . . .
</distributed-cache>

Screenshot_45

Screenshot_46

By definition, the choice between replication and distribution depends largely on the cluster size. For example, replication provides a quick and easy way to share state across a cluster; however, it only performs well in small clusters (fewer than ten servers), due to the number of replication messages that need to happen—as the cluster
size increases.

In a distributed cache, a number of copies are maintained to provide redundancy and fault tolerance; however, this is typically far fewer than the number of nodes in the cluster. Hence, a distributed cache provides a far greater degree of scalability than a replicated cache.

Does Infinispan use buddy replication?

Buddy replication was the most effective solution for scaling web applications in earlier releases of JBoss AS. The major advantage of buddy replication was that, instead of replicating data across every node of the cluster, it chose a fixed number of backup nodes and only replicated data to these backups.

A quite helpful thing but with one caveat: buddy replication was specifically designed for HTTP-session replication. This in turn requires, for achieving a real performance benefit, the use of session affinity, also known as sticky sessions in HTTP session replication speak.

As we have been using the past tense, you might guess that a buddy replication has been abandoned in JBoss AS 7. The Infinispan’s distribution mode is the functional replacement of buddy replication.

While providing a near-linear scalable solution, by using a fixed number of owners to hold the cache data, it does not need session affinity. Hence, it is applicable to a wider set of use cases than HTTP session.


0 Responses on Configuring session cache containers"

Leave a Message

Your email address will not be published. Required fields are marked *

Copy Rights Reserved © Mindmajix.com All rights reserved. Disclaimer.
Course Adviser

Fill your details, course adviser will reach you.