Chapter 5. Cache Modes
5.1. Cache Modes
Red Hat JBoss Data Grid provides two modes:
- Local mode is the only non-clustered cache mode offered in JBoss Data Grid. In local mode, JBoss Data Grid operates as a simple single-node in-memory data cache. Local mode is most effective when scalability and failover are not required and provides high performance in comparison with clustered modes.
- Clustered mode replicates state changes to a subset of nodes. The subset size should be sufficient for fault tolerance purposes, but not large enough to hinder scalability. Before attempting to use clustered mode, it is important to first configure JGroups for a clustered configuration. For details about configuring JGroups, see Configure JGroups (Library Mode)
5.2. About Cache Containers
Cache containers are used in Red Hat JBoss Data Grid’s Remote Client-Server mode as a starting point for a cache. The
cache-container element acts as a parent of one or more (local or clustered) caches. To add clustered caches to the container, transport must be defined.
The following procedure demonstrates a sample cache container configuration:
How to Configure the Cache Container
<subsystem xmlns="urn:infinispan:server:core:8.4" default-cache-container="local"> <cache-container name="local" default-cache="default" statistics="true" start="EAGER"> <local-cache name="default" statistics="false"> <!-- Additional configuration information here --> </local-cache> </cache-container> </subsystem>
Configure the Cache Container
cache-containerelement specifies information about the cache container using the following parameters:
nameparameter defines the name of the cache container.
default-cacheparameter defines the name of the default cache used with the cache container.
statisticsattribute is optional and is
trueby default. Statistics are useful in monitoring JBoss Data Grid via JMX or JBoss Operations Network, however they adversely affect performance. Disable this attribute by setting it to
falseif it is not required.
startparameter indicates when the cache container starts, i.e. whether it will start lazily when requested or "eagerly" when the server starts up. Valid values for this parameter are
Configure Per-cache Statistics
statisticsare enabled at the container level, per-cache statistics can be selectively disabled for caches that do not require monitoring by setting the
5.3. Local Mode
5.3.1. Local Mode
Using Red Hat JBoss Data Grid’s local mode instead of a map provides a number of benefits.
Caches offer features that are unmatched by simple maps, such as:
- Write-through and write-behind caching to persist data.
- Entry eviction to prevent the Java Virtual Machine (JVM) running out of memory.
- Support for entries that expire after a defined period.
JBoss Data Grid is built around a high performance, read-based data container that uses techniques such as optimistic and pessimistic locking to manage lock acquisitions.
JBoss Data Grid also uses compare-and-swap and other lock-free algorithms, resulting in high throughput multi-
CPU or multi-core environments. Additionally, JBoss Data Grid’s Cache
API extends the
ConcurrentMap, resulting in a simple migration process from a map to JBoss Data Grid.
5.3.2. Configure Local Mode
A local cache can be added to any cache container in both Library Mode and Remote Client-Server Mode. The following example demonstrates how to add the
<cache-container name="local" default-cache="default" statistics="true"> <local-cache name="default" statistics="true"> <!-- Additional configuration information here --> </local-cache> </cache-container>
local-cache element specifies information about the local cache used with the cache container using the following parameters: . The
name parameter specifies the name of the local cache to use. . If
statistics are enabled at the container level, per-cache statistics can be selectively disabled for caches that do not require monitoring by setting the
statistics attribute to
Local and clustered caches are able to coexist in the same cache container, however where the container is without a
<transport/> it can only contain local caches. The container used in the example can only contain local caches as it does not have a
The cache interface extends the ConcurrentMap and is compatible with multiple cache systems.
5.4. Clustered Modes
5.4.1. Clustered Modes
Red Hat JBoss Data Grid offers the following clustered modes:
- Replication Mode replicates any entry that is added across all cache instances in the cluster.
- Invalidation Mode does not share any data, but signals remote caches to initiate the removal of invalid entries.
- Distribution Mode stores each entry on a subset of nodes instead of on all nodes in the cluster.
The clustered modes can be further configured to use synchronous or asynchronous transport for network communications.
5.4.2. Asynchronous and Synchronous Operations
When a clustered mode (such as invalidation, replication or distribution) is used, data is propagated to other nodes in either a synchronous or asynchronous manner.
If synchronous mode is used, the sender waits for responses from receivers before allowing the thread to continue, whereas asynchronous mode transmits data but does not wait for responses from other nodes in the cluster to continue operations.
Asynchronous mode prioritizes speed over consistency, which is ideal for use cases such as HTTP session replications with sticky sessions enabled. Such a session (or data for other use cases) is always accessed on the same cluster node, unless this node fails.
By default the cluster is configured for synchronous operations.
5.4.3. About Asynchronous Communications
In Red Hat JBoss Data Grid, the local, distributed and replicated modes are represented by the
replicated-cache elements respectively. Each of these elements contains a
mode property, the value of which can be set to
SYNC for synchronous or
ASYNC for asynchronous communications.
Asynchronous Communications Example Configuration
<replicated-cache name="default" statistics="true"> <!-- Additional configuration information here --> </replicated-cache>
This configuration is valid for both JBoss Data Grid’s usage modes (Library mode and Remote Client-Server mode).
5.4.4. Cache Mode Troubleshooting
188.8.131.52. Invalid Data in ReadExternal
If invalid data is passed to
readExternal, it can be because when using
Cache.putAsync(), starting serialization can cause your object to be modified, causing the datastream passed to
readExternal to be corrupted. This can be resolved if access to the object is synchronized.
184.108.40.206. Cluster Physical Address Retrieval
How can the physical addresses of the cluster be retrieved?
The physical address can be retrieved using an instance method call. For example: AdvancedCache.getRpcManager().getTransport().getPhysicalAddresses() .