当满足JVM上配置的最小可用堆百分比时,Hazelcast的FREE_HEAP_PERCENTAGE
最大大小策略不会驱逐映射条目。
以下是一个说明此问题的测试用例。如果测试与其他策略类型(包括USED_HEAP_PERCENTAGE
)一起运行,则它按预期工作,以便在达到此最大大小时逐出条目。但是,如果它使用FREE_HEAP_PERCENTAGE
运行,则不会从地图中逐出条目,尽管可用堆百分比超出允许的百分比(例如,如果运行管理中心可以确认)。
public class HazelcastMaxSizeTest {
private static final String GROUP_NAME = "TEST";
private static final String MAP_NAME = "test";
private static MaxSizeConfig POLICY_THAT_WORKS = new MaxSizeConfig(5, MaxSizeConfig.MaxSizePolicy.USED_HEAP_PERCENTAGE);
private static MaxSizeConfig POLICY_THAT_DOES_NOT_WORK = new MaxSizeConfig(99, MaxSizeConfig.MaxSizePolicy.FREE_HEAP_PERCENTAGE);
public static void main(String[] args) throws Exception {
HazelcastInstance instance = startHazelcast("hazelcast1", POLICY_THAT_DOES_NOT_WORK);
System.out.println("started " + instance.getName());
IMap<Long, byte[]> map = createMap(instance, MAP_NAME);
System.out.println("map size: " + map.size());
instance.shutdown();
}
private static HazelcastInstance startHazelcast(String instanceName, MaxSizeConfig maxSizeConfig) {
MapConfig mapConfig = new MapConfig(MAP_NAME);
mapConfig.setMaxSizeConfig(maxSizeConfig);
mapConfig.setStatisticsEnabled(true);
mapConfig.setEvictionPolicy(EvictionPolicy.LRU);
mapConfig.setMinEvictionCheckMillis(0L);
mapConfig.setBackupCount(1);
Config config = new Config(instanceName);
config.addMapConfig(mapConfig);
config.getManagementCenterConfig().setEnabled(true);
config.getManagementCenterConfig().setUrl("http://localhost:8080/mancenter");
config.getGroupConfig().setName(GROUP_NAME).setPassword(GROUP_NAME);
return Hazelcast.getOrCreateHazelcastInstance(config);
}
private static IMap<Long, byte[]> createMap(HazelcastInstance instance, String mapname) {
IMap<Long, byte[]> map = instance.getMap(mapname);
map.addEntryListener(new EntryEvictedListener<Long, byte[]>() {
@Override
public void entryEvicted(EntryEvent<Long, byte[]> event) {
System.out.println("evicted " + event.getName() + ": " + event.getKey());
}
}, false);
for (long i = 1; i <= 50_000; i++) {
map.set(i, new byte[100]);
if (i % 1000 == 0) {
System.out.println("set " + map.getName() + ": " + i);
}
}
return map;
}
}
经过一些进一步的调试后,我想知道Hazelcast EvictionChecker
是否可能错误地计算了免费堆百分比。在调试时,我发现计算出的可用堆百分比大于100.它的计算使用available / total
,但如here所述,这可能应该是available / max
?< / p>
我的配置或预期使用FREE_HEAP_PERCENTAGE
政策是否有问题?或者这是一个Hazelcast的错误?
规格:Hazelcast 3.6,-Xmx256m
答案 0 :(得分:2)
经过进一步调试后,我发现FREE_HEAP_PERCENTAGE
策略的意外行为是由于Hazelcast计算可用内存中的错误造成的。此问题已在Hazelcast的问题跟踪器中报告为Issue 7599。