Este conteúdo não está disponível no idioma selecionado.
3.3. Using Eviction
In Red Hat JBoss Data Grid, eviction is disabled by default. If an empty <
eviction /> element is used to enable eviction without any strategy or maximum entries settings, the following default values are automatically implemented:
- Strategy: If no eviction strategy is specified,
EvictionStrategy.NONEis assumed as a default. - max-entries/maxEntries: If no value is specified, the
max-entries/maxEntries value is set to-1, which allows unlimited entries.
3.3.1. Initialize Eviction Copiar o linkLink copiado para a área de transferência!
Copiar o linkLink copiado para a área de transferência!
To initialize eviction, set the eviction element's
max-entries attributes value to a number greater than zero. Adjust the value set for max-entries to discover the optimal value for your configuration. It is important to remember that if too large a value is set for max-entries, Red Hat JBoss Data Grid runs out of memory.
The following procedure outlines the steps to initialize eviction in JBoss Data Grid:
Procedure 3.1. Initialize Eviction
Add the Eviction Tag
Add the <eviction> tag to your project's <cache> tags as follows:<eviction />
<eviction />Copy to Clipboard Copied! Toggle word wrap Toggle overflow Set the Eviction Strategy
Set thestrategyvalue to set the eviction strategy employed. Possible values areLRU,UNORDEREDandLIRS(orNONEif no eviction is required). The following is an example of this step:<eviction strategy="LRU" />
<eviction strategy="LRU" />Copy to Clipboard Copied! Toggle word wrap Toggle overflow Set the Maximum Entries
Set the maximum number of entries allowed in memory. The default value is-1for unlimited entries.- In Library mode, set the
maxEntriesparameter as follows:<eviction strategy="LRU" maxEntries="200" />
<eviction strategy="LRU" maxEntries="200" />Copy to Clipboard Copied! Toggle word wrap Toggle overflow - In Remote Client Server mode, set the
max-entriesas follows:<eviction strategy="LRU" max-entries="200" />
<eviction strategy="LRU" max-entries="200" />Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Result
Eviction is configured for the target cache.
3.3.2. Eviction Configuration Examples Copiar o linkLink copiado para a área de transferência!
Copiar o linkLink copiado para a área de transferência!
Configure eviction in Red Hat JBoss Data Grid using the configuration bean or the XML file. Eviction configuration is done on a per-cache basis.
- A sample XML configuration for Library mode is as follows:
<eviction strategy="LRU" maxEntries="2000"/>
<eviction strategy="LRU" maxEntries="2000"/>Copy to Clipboard Copied! Toggle word wrap Toggle overflow - A sample XML configuration for Remote Client Server Mode is as follows:
<eviction strategy="LRU" max-entries="20"/>
<eviction strategy="LRU" max-entries="20"/>Copy to Clipboard Copied! Toggle word wrap Toggle overflow - A sample programmatic configuration for Library Mode is as follows:
Configuration c = new ConfigurationBuilder().eviction().strategy(EvictionStrategy.LRU) .maxEntries(2000) .build();Configuration c = new ConfigurationBuilder().eviction().strategy(EvictionStrategy.LRU) .maxEntries(2000) .build();Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Note
JBoss Data Grid's Library mode uses the
maxEntries parameter while Remote Client-Server mode uses the max-entries parameter to configure eviction.
3.3.3. Eviction Configuration Troubleshooting Copiar o linkLink copiado para a área de transferência!
Copiar o linkLink copiado para a área de transferência!
In Red Hat JBoss Data Grid, the size of a cache can be larger than the value specified for the
max-entries parameter of the eviction element. This is because although the max-entries value can be configured to a value that is not a power of two, the underlying algorithm will alter the value to V, where V is the closest power of two value that is larger than the max-entries value. Eviction algorithms are in place to ensure that the size of the cache container will never exceed the value V.
3.3.4. Eviction and Passivation Copiar o linkLink copiado para a área de transferência!
Copiar o linkLink copiado para a área de transferência!
To ensure that a single copy of an entry remains, either in memory or in a cache store, use passivation in conjunction with eviction.
The primary reason to use passivation instead of a normal cache store is that updating entries require less resources when passivation is in use. This is because passivation does not require an update to the cache store.