- 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.
- Learning LibGDX Game Development(Second Edition)
- Java Web開發學習手冊
- Visual Basic 6.0程序設計計算機組裝與維修
- Python Game Programming By Example
- React.js Essentials
- Python神經網絡項目實戰
- Building Serverless Applications with Python
- Mastering C++ Multithreading
- Building Serverless Architectures
- C++ Fundamentals
- SQL Server 入門很輕松(微課超值版)
- Vue.js 3應用開發與核心源碼解析
- OpenCV Android開發實戰
- Java Hibernate Cookbook
- 軟硬件綜合系統軟件需求建模及可靠性綜合試驗、分析、評價技術