1 2 Previous Next 21 Replies Latest reply on Jul 19, 2010 4:05 PM by vblagojevic

    How is the parameter maxEntries interpreted by the Eviction Algorithms?

    nfilotto

      Hi All,

       

      I'm evaluating infinispan 4.1.0.BETA2 to ensure that JBoss Cache cans be replaced with Infinispan in my product. During my study, I've noticed that the parameter maxEntries is strangely managed by the Eviction Algorithms, I don't know if it is a bug so I prefer to ask first but it looks like it. I expect that the cache size never exceeds the maximum amount of entries after the eviction thread woke up however according to the following Unit Test, it doesn't seem to be true. See the code below:

      {code}

      import junit.framework.TestCase;
      import org.infinispan.Cache;
      import org.infinispan.config.Configuration;
      import org.infinispan.eviction.EvictionStrategy;
      import org.infinispan.manager.CacheManager;
      import org.infinispan.manager.DefaultCacheManager;
      public class TestEviction extends TestCase
      {
         public void testFIFOMaxEntries() throws Exception
         {
            Configuration c = new Configuration();
            int maxEntries = 10;
            c.setEvictionStrategy(EvictionStrategy.FIFO);
            c.setEvictionMaxEntries(maxEntries);
            c.setEvictionWakeUpInterval(500);
            CacheManager manager = new DefaultCacheManager(c);
            Cache<String, String> cache = manager.getCache();
            int totalKeys = 20;
            for (int i = 0; i < totalKeys; i++)
            {
               cache.put("key-" + (i + 1), "value-" + (i + 1));       
            }
            Thread.sleep(1000);
            assertEquals(maxEntries, cache.size());
         }
       
         public void testLRUMaxEntries() throws Exception
         {
            Configuration c = new Configuration();
            int maxEntries = 10;
            c.setEvictionStrategy(EvictionStrategy.LRU);
            c.setEvictionMaxEntries(maxEntries);
            c.setEvictionWakeUpInterval(500);
            CacheManager manager = new DefaultCacheManager(c);
            Cache<String, String> cache = manager.getCache();
            int totalKeys = 20;
            for (int i = 0; i < totalKeys; i++)
            {
               cache.put("key-" + (i + 1), "value-" + (i + 1));       
            }
            Thread.sleep(1000);
            assertEquals(maxEntries, cache.size());
         }
         
         public void testLIRSMaxEntries() throws Exception
         {
            Configuration c = new Configuration();
            int maxEntries = 10;
            c.setEvictionStrategy(EvictionStrategy.LIRS);
            c.setEvictionMaxEntries(maxEntries);
            c.setEvictionWakeUpInterval(500);
            CacheManager manager = new DefaultCacheManager(c);
            Cache<String, String> cache = manager.getCache();
            int totalKeys = 20;
            for (int i = 0; i < totalKeys; i++)
            {
               cache.put("key-" + (i + 1), "value-" + (i + 1));       
            }
            Thread.sleep(1000);
            assertEquals(maxEntries, cache.size());
         }  
       
         public void testUNORDEREDMaxEntries() throws Exception
         {
            Configuration c = new Configuration();
            int maxEntries = 10;
            c.setEvictionStrategy(EvictionStrategy.UNORDERED);
            c.setEvictionMaxEntries(maxEntries);
            c.setEvictionWakeUpInterval(500);
            CacheManager manager = new DefaultCacheManager(c);
            Cache<String, String> cache = manager.getCache();
            int totalKeys = 20;
            for (int i = 0; i < totalKeys; i++)
            {
               cache.put("key-" + (i + 1), "value-" + (i + 1));       
            }
            Thread.sleep(1000);
            assertEquals(maxEntries, cache.size());
         } 
      }

      {code}

       

      Is-it normal? If so how can we know the effective value of the max entries?

       

      Thank you in advance for your answers,

      BR,

      Nicolas

       

      Ce message a été modifié par: Nicolas Filotto

        1 2 Previous Next