问题
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>
Here is the default memory usage after I start the engine with 0.5GB heap:
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!
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.
EDIT
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.
回答1:
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).
来源:https://stackoverflow.com/questions/35087485/ignite-doesnt-free-memory-after-cache-destroy