Sizing Distributed Caches
Terracotta distributed caches can be sized as other caches except that they do not use the local disk and therefore cannot be configured with *LocalDisk sizing attributes. Distributed caches use the storage resources available on the Terracotta Server Array, BigMemory Max and the Fast Restart store. For more information about fast restartability for distributed caches, see "Terracotta Cluster with Reliability" in the Terracotta Server Array Administrator Guide.
Cache-configuration sizing attributes behave as local configuration, which means that every node can load its own sizing attributes for the same caches. That is, while some elements and attributes are fixed by the first Ehcache configuration loaded in the cluster, cache-configuration sizing attributes can vary across nodes for the same cache.
For example, a cache may have the following configuration on one node:
<cache name="myCache"
maxEntriesLocalHeap="10000"
maxBytesLocalOffHeap="8g"
eternal="false"
timeToIdleSeconds="3600"
timeToLiveSeconds="1800">
<persistence strategy="distributed"/>
<terracotta/>
</cache>
The same cache may have the following size configuration on another node:
<cache name="myCache"
maxEntriesLocalHeap="10000"
maxBytesLocalOffHeap="10g"
eternal="false"
timeToIdleSeconds="3600"
timeToLiveSeconds="1800">
<persistence strategy="distributed"/>
<terracotta/>
</cache>
If the cache exceeds its size constraints on a node, then with this configuration the Terracotta Server Array provides myCache with an unlimited amount of space for spillover and backup. To impose a limit, you must set maxEntriesInCache to a positive non-zero value:
<cache name="myCache"
maxEntriesLocalHeap="10000"
maxBytesLocalOffHeap="10g"
eternal="false"
timeToIdleSeconds="3600"
timeToLiveSeconds="1800"
maxEntriesInCache="1000000">
<persistence strategy="distributed"/>
<terracotta/>
</cache>
The Terracotta Server Array will now evict myCache entries to stay within the limit set by maxEntriesInCache. However, for any particular cache, eviction on the Terracotta Server Array is based on the largest size configured for that cache. In addition, the Terracotta Server Array will not evict any cache entries that exist on at least one client node, regardless of the limit imposed by maxEntriesInCache.
Note: | If maxEntriesInCache is not set, the default value 0 is used, which means that the cache is unbounded and will not undergo capacity eviction (but periodic and resource evictions are still allowed). Although bounds are not enforced by capacity eviction, an "unbounded" cache in this respect has a practical limitation equal to Integer.MAX_VALUE (app. 2 billion entries). For more information about eviction, see "Understanding Automatic Resource Management" in the Terracotta Server Array Administrator Guide. |
Sizing the Terracotta Server Array
Since maxEntriesInCache is based on entries, you must size the Terracotta Server Array based on the expected average size of an entry. One way to discover this value is by using the Terracotta Management Console (TMC). Set up a test cluster with the expected data set, and connect it to the TMC. Then navigate to Application Data > Sizing Panel, and review the Relative Cache Sizes by Tier section.
Note that the average cache-entry size reported in the TMC is an estimate. For more information, see the Terracotta Management Console User Guide.