我试图将一些对象放入缓存中。
使用 Hazelcast,当我放置大约 30 个对象时,我的内存不足。
但是,使用 ehCache 3,我可以毫无问题地放置 1000 个。
我是否正确使用 Hazelcast?
雾霾天气:
Config config = new Config().addCacheConfig(new
CacheSimpleConfig().setName("testCache"));
config.setInstanceName("hzInstanceTest");
HazelcastInstance instance = Hazelcast.newHazelcastInstance(config);
List<CaLpgDataRowDto<CaBigNumber>> bigList = lpgDatasource.getDataRows();
while (bigList.size() <= 5000000)
{
bigList.addAll(bigList);
}
lpgDatasource.setDataRows(bigList);
ICacheManager hazelcastCacheManager = instance.getCacheManager();
ICache<String, CaLpgDataCollectionDto<CaBigNumber>> cache = hazelcastCacheManager.getCache("testCache");
System.out.println("Free memory before (bytes): " + Runtime.getRuntime().freeMemory());
for (int i = 0; i < 33 ; i++)
{
cache.put("objectTest"+i, lpgDatasource);
}
System.out.println("Free memory after (bytes): " + Runtime.getRuntime().freeMemory());
EHCACHE 3:
CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder()
.withCache("ehInstanceTest",
CacheConfigurationBuilder
.newCacheConfigurationBuilder(String.class, CaLpgDataCollectionDto.class, ResourcePoolsBuilder
.heap(10)))
.build();
cacheManager.init();
Cache<String, CaLpgDataCollectionDto> testCache = cacheManager.createCache("testCache",
CacheConfigurationBuilder.newCacheConfigurationBuilder(String.class, CaLpgDataCollectionDto.class, ResourcePoolsBuilder.heap(1000)));
List<CaLpgDataRowDto<CaBigNumber>> bigList = lpgDatasource.getDataRows();
while (bigList.size() <= 5000000)
{
bigList.addAll(bigList);
}
lpgDatasource.setDataRows(bigList);
System.out.println("Free memory before (bytes): " + Runtime.getRuntime().freeMemory());
for (int i = 0; i < 1000 ; i++)
{
testCache.put("objectTest"+i,lpgDatasource);
}
System.out.println("Free memory after (bytes): " + Runtime.getRuntime().freeMemory());