when will EvictionPolicy start to deltete data? and how it works?

42 Views Asked by At

I'v useing LruEvictionPolicyFactory in my CacheConfiguration like blow

CacheConfiguration<K, V> cacheCfg = new CacheConfiguration<>();
cacheCfg.setDataRegionName("ds_name");
cacheCfg.setAtomicityMode(CacheAtomicityMode.ATOMIC);
cacheCfg.setRebalanceMode(CacheRebalanceMode.ASYNC);
cacheCfg.setPartitionLossPolicy(PartitionLossPolicy.READ_WRITE_SAFE);
cacheCfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.PRIMARY_SYNC);
cacheCfg.setEvictionPolicyFactory(new LruEvictionPolicyFactory<>(200000));

and I use DataRegionConfig like this

     <bean class="org.apache.ignite.configuration.DataRegionConfiguration">
        <property name="name" value="ds_name"/>      
        <property name="initialSize" value="#{512L * 1024 * 1024}"/>
        <property name="maxSize" value="#{3 * 1024L * 1024 * 1024}"/>
        <property name="pageEvictionMode" value="RANDOM_LRU"/>
        <property name="evictionThreshold" value="0.9"/>
        <property name="metricsEnabled" value="true"/>
        <property name="persistenceEnabled" value="false"/>
     </bean>

but I can see far more than 2000000 records in my cache, for some times, i can see 800000 records in the cache

how to control data size in my cache to avoid one cache using too many memories

1

There are 1 best solutions below

2
Vladimir Pligin On

Your data region configuration seems to be more or less correct according to this doc page. I would recommend using RANDOM_2_LRU and configure a data region name to use it for the reference.

 <bean class="org.apache.ignite.configuration.DataRegionConfiguration">      
    <property name="initialSize" value="#{512L * 1024 * 1024}"/>
    <property name="name" value="region_name"/>
    <property name="maxSize" value="#{3 * 1024L * 1024 * 1024}"/>
    <property name="pageEvictionMode" value="RANDOM_LRU"/>
    <property name="evictionThreshold" value="0.9"/>
    <property name="metricsEnabled" value="true"/>
    <property name="persistenceEnabled" value="false"/>
 </bean>

In turn your CacheConfiguration doesn't contain the dataRegionName parameter. For example:

CacheConfiguration<K, V> cacheCfg = new CacheConfiguration<>();
cacheCfg.setAtomicityMode(CacheAtomicityMode.ATOMIC);
cacheCfg.setRebalanceMode(CacheRebalanceMode.ASYNC);
cacheCfg.setPartitionLossPolicy(PartitionLossPolicy.READ_WRITE_SAFE);
cacheCfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.PRIMARY_SYNC);
cacheCfg.setDataRegionName("region_name");