- Getting Started with Hazelcast(Second Edition)
- Mat Johns
- 617字
- 2021-07-16 13:14:36
What happens when we reach our limits?
As large as we might be able to scale a cluster to handle the ever-growing datasets, it is quite possible that we will want to configure a map so that it features a specific behavior. The things that we can customize are the number of backup counts and types, limits on how big a particular map can grow, plus what we can do when we reach that limit, and the defining of a default lifespan for the entries. We can use the hazelcast.xml
configuration to define this behavior for all the maps or for an inpidual one. Now, we can copy the configuration from the unpacked download bin/hazelcast.xml
to our working directory, which should be on the Java classpath, and add a custom configuration for the capitals
map, as follows:
<map name="capitals"> <max-size policy="PER_NODE">10</max-size> <eviction-policy>LFU</eviction-policy> <eviction-percentage>20</eviction-percentage> <backup-count>1</backup-count> <async-backup-count>1</async-backup-count> <time-to-live-seconds>86400</time-to-live-seconds> <max-idle-seconds>3600</max-idle-seconds> </map>
The properties that we have put in place should all be relatively self-explanatory, but let's go through them in a little more detail, as there are a few properties that demand closer inspection. The first set deals with bounding the size of the map and what to do when the limit of the map is reached.
The max-size
parameter, as you would expect, governs how big a map can grow before we have a clear out and evict the existing entries to make room for the potential ones that may be created in the future. However, we can additionally pick any of the six types of policies to vary this behavior.
The first (and the default) policy is the easiest to understand:
PER_NODE
- The maximum number of entries per node
The second one is probably the least useful in a real-world scenario.
PER_PARTITION
- The maximum number of entries per internal partition slice
- The number of partitions is also configurable, but as a cluster-wide parameter rather than something that is specific to any one map
The latter policies are related to the usage of an inpidual node's heap.
USED_HEAP_SIZE
- The maximum heap usage in megabytes
USED_HEAP_PERCENTAGE
- The maximum proportion of the total heap size
FREE_HEAP_SIZE
- The minimum heap usage in megabytes (the inverse of the above)
FREE_HEAP_PERCENTAGE
- The minimum proportion of the total heap size (the inverse of the above)
The eviction-policy
governs the strategy that is used to select the entries that should be discarded when making room for the new ones. There are a few options to pick from:
- NONE
- No eviction (default)
- Least Recently Used (LRU)
- The oldest interacted with entries
- Least Frequency Used (LFU)
- The least interacted with entries
The eviction-percentage
dictates when we trigger an eviction and how much space we preemptively need to create relative to the overall max-size of the map.
The next set of configurations deals with the backup copies of entries, both in terms of the number of duplicate copies to hold as well as the method and consistency of how they are created.
- The
backup-count
controls the number of backup copies that can be created synchronously on each change. Increasing this number significantly will have performance implications, as update operations will have to block awaiting receipt of confirmations from this many of backup nodes. - The
async-backup-count
controls the number of backup copies that are created asynchronously on a best-efforts basis. This figure, combined with thebackup-count
, determines the total number of backup copies that should be held.
The final set is used to set a map-wide default TTL for entries:
- The
time-to-live-seconds
is a default dumb TTL for each entry. Entities will be removed from the map after this amount of time, irrespective of use or resetting when overwritten. - The
max-idle-seconds
sets the maximum time that an entry can remain unused before it expires.
- Practical Data Analysis Cookbook
- Deploying Node.js
- Beginning Java Data Structures and Algorithms
- SQL Server 2012數(shù)據(jù)庫技術(shù)及應(yīng)用(微課版·第5版)
- HTML5 移動(dòng)Web開發(fā)從入門到精通(微課精編版)
- 深度學(xué)習(xí):算法入門與Keras編程實(shí)踐
- 量化金融R語言高級教程
- Mastering Android Development with Kotlin
- Getting Started with LLVM Core Libraries
- Java系統(tǒng)化項(xiàng)目開發(fā)教程
- 區(qū)塊鏈底層設(shè)計(jì)Java實(shí)戰(zhàn)
- Corona SDK Mobile Game Development:Beginner's Guide(Second Edition)
- C語言開發(fā)基礎(chǔ)教程(Dev-C++)(第2版)
- Android移動(dòng)開發(fā)案例教程:基于Android Studio開發(fā)環(huán)境
- Java語言程序設(shè)計(jì)教程