Is MaxSizeConfig broken? I expect map to contain maximum 2000 entries and only then start evicting old entries, however when I insert 2000 entries, I get 340 evictions.
@Bean
public Config hazelCastConfig() {
Config config = new Config();
config.setProperty("hazelcast.logging.type", "slf4j");
// config.setProperty("hazelcast.partition.count", "2");
MapConfig mapConfig = new MapConfig()
.setBackupCount(0)
.setName("map")
.setEvictionPolicy(EvictionPolicy.LRU)
.setMaxSizeConfig(new MaxSizeConfig(2000, MaxSizeConfig.MaxSizePolicy.PER_NODE))
.addEntryListenerConfig(new EntryListenerConfig(new ExampleEntryListener(), false, true));
config.addMapConfig(mapConfig);
return config;
}
Found this formula about eviction: https://docs.hazelcast.org/docs/3.12/manual/html-single/index.html#understanding-map-eviction
partition-maximum-size = max-size * member-count / partition-count
In my case it's, partition-count=271, member-count=1 (running spring-boot app with hazelcast instance embedded). So to get 2000 stored guaranteed, max-size needs to be:
max-size = partition-maximum-size * partition-count / member-count
max-size = 2000 * 271 / 1 = 471000
471000 seems too big number for only 2000 entries. When I set max-size=6000 hazelcast seems to keep at least 2000 entries.
Question: What's wrong with my config/formula? How can I configure hazelcast to hold strictly X entries PER_NODE. So when app is deployed with (1 node for TEST and 2 nodes for PRELIVE) hazelcast forms cluster of 2 (or 1) members, there is 2000 entries held inside cluster and not more, without calculating anything with fancy formulas and just specifying 2000?