BigMemory 4.3.9 | Code Samples | Example: Automatic Resource Control
 
Example: Automatic Resource Control
Note:
The following description focuses on code snippets from the full code example, which is available at the /code-samples/src/ location in the installed product kit.
Automatic Resource Control (ARC) is a powerful capability of BigMemory Max that gives you the ability to control how much data is stored in heap memory and off-heap memory.
The following XML configuration instructs ARC to allocate a maximum of 512 M of heap memory and 8 G of off-heap memory. In this example, when 512 M of heap memory is used, ARC will automatically move data into off-heap memory up to a maximum of 8 G. The amount of off-heap memory you can use is limited only by the amount of physical RAM you have available.
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd"
updateCheck="false" monitoring="autodetect"
dynamicConfig="true"
name="MyManager" maxBytesLocalHeap="512M"
maxBytesLocalOffHeap="8G">
<defaultCache>
</defaultCache>
<cache name="BigMemory1">
</cache>
<cache name="BigMemory2">
</cache>
</ehcache>
This instructs the ARC capability of BigMemory to keep a maximum of 512 MB of its data in heap for nanosecond to microsecond access. In this example, as the 512 MB of heap memory fills up, ARC will automatically move data to the 8 GB off-heap store where it is available at microsecond speed. This configuration keeps heap sizes small to avoid garbage collection pauses and tuning, but still uses large amounts of in-process memory for ultra-fast access to data.
Important:
BigMemory Max is capable of addressing gigabytes to terabytes of in-memory data in a single JVM. However, to avoid swapping, take care not to configure BigMemory Max to use more memory than is physically available on your hardware.
It's also possible to allocate resources on a per-data set basis. Here is an example of allocating 8 GB of off-heap memory to the BigMemory1 data set and 24 GB of off-heap memory to the BigMemory2 data set:
<ehcache xmlns
...
name="MyManager"
maxBytesLocalHeap="512M"
maxBytesLocalOffHeap="32G"
maxBytesLocalDisk="128G">
<cache name="BigMemory1"
maxBytesLocalOffHeap="8G">
</cache>
<cache name="BigMemory2"
maxBytesLocalOffHeap="24G">
</cache>
</ehcache>