问题描述
我将Ignite引擎用作Spring引导Web应用程序中的Bean.缓存配置如下:
I'm using Ignite engine as a bean inside a Spring boot web application. The cache configuration is as follows:
<bean id="ignite" class="org.apache.ignite.IgniteSpringBean">
<property name="configuration">
<bean id="ignite.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
<property name="cacheConfiguration">
<list>
<bean class="org.apache.ignite.configuration.CacheConfiguration">
<property name="atomicityMode" value="TRANSACTIONAL" />
<property name="cacheMode" value="PARTITIONED" />
<property name="backups" value="0" />
<property name="startSize" value="#{1024*16}" />
<property name="memoryMode" value="OFFHEAP_TIERED" />
<property name="offHeapMaxMemory" value="#{1 * 1024L * 1024L * 1024L}" />
<property name="swapEnabled" value="true" />
<property name="evictSynchronized" value="true" />
</bean>
</list>
</property>
<property name="swapSpaceSpi">
<bean class="org.apache.ignite.spi.swapspace.file.FileSwapSpaceSpi">
<property name="baseDirectory" value="..." />
</bean>
</property>
这是我以0.5GB的堆启动引擎后的默认内存使用情况:
Here is the default memory usage after I start the engine with 0.5GB heap:
现在我期望最大内存使用量为2.6 GB,因为我将堆外最大内存设置为1 GB.但是,当我将数百万个对象加载到缓存后,会发生什么!
Now at this point I'm expecting the maximum memory usage to be 2.6 GB since I set the off-heap max memory to 1 GB. But here is what happens after I load some million objects into cache!
更糟糕的是,我破坏了缓存,但内存使用率仍然存在!
What's even worse is, I destroy the cache but the memory usage is still there!
在这一点上,如果我尝试将更多条目加载到缓存中,则内存使用量一直在增长,这证明ignit无法释放我之前销毁的缓存.
At this point if I try to load more entries into cache, the memory usage just keeps growing, proving that ignite didn't free the cache I destroyed earlier.
编辑
我将一个maven测试项目及其输出上传到 http://sourceforge.net/projects/ignitetest35087485/files/.正如您将看到的,它在5个负载破坏周期后耗尽了我的记忆.没有发生交换空间的问题,并且没有将offHeapMaxMemory设置考虑为点燃.
I uploaded a maven test project along with my output to http://sourceforge.net/projects/ignitetest35087485/files/. As you will see, it depleted my memory after 5 cycles of load-destroy. Eviction to swap space did not take place and ignite didn't take the offHeapMaxMemory setting into account.
这是什么问题?非常感谢您的帮助.
What is the problem here? Any help is much appreciated.
推荐答案
对我有用的唯一方法是调用Cache#removeAll + Ignite#destroyCache + Ignite#createCache.这样,我就可以使用新的/更新的配置创建新的缓存,并在创建新的缓存之前解锁过时的堆外内存.这样可以根据需要缩小和增加内存量.如果您知道自己有绝对最大值.无需缩小它,您只需配置off-heap-max-memory(+ EvictionPolicy和ExpiryPolicy),然后将重新使用未使用的空间(您将无法摆脱Off-heap-max-memory,但是缓存也不会缩小).
The only way which worked for me is to call Cache#removeAll + Ignite#destroyCache + Ignite#createCache. With that I was able to create a new cache with a new/updated config and unlocking the outdated off-heap memory before creating the new cache. That allows to shrink and grow the amount of memory as you need. If you know that you have an absolute max. and no need to shrink it, you can just configure the off-heap-max-memory (+ EvictionPolicy and ExpiryPolicy) and the unused space will be re-used (you won't get over off-heap-max-memory, but the cache also won't shrink).
这篇关于缓存破坏后,Ignite不会释放内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!