3 Replies Latest reply on Sep 15, 2009 12:26 PM by Galder Zamarreño

    Eviction problems: Thread executing before specified time an

    Andres Pachon Newbie

      Hi guys,

      I'm testing JBoss Cache Cascabel on JBoss AS 5 and Mac OSX. I tried to do a simple proof of concept specifying a LRU eviction algorithm and a wakeUpInterval equal to 10 seconds. However, I'm struggling with the following issues:

      1. The eviction thread is executing in half of the specified time. For instance, I set the wakeUpInterval parameter to 10 000 (10 sec) but I see in the log files that it is executed every 5 seconds.

      2. The LRU is removing the wrong nodes, in this case, is removing the MOST Recently Used nodes, not the LEAST recently used nodes, as it is supposed to be.

      Find below the config file I'm using.

      <?xml version="1.0" encoding="UTF-8"?>
      <jbosscache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:jboss:jbosscache-core:config:3.1">
      
      <transaction transactionManagerLookupClass="org.jboss.cache.transaction.GenericTransactionManagerLookup"/>
      
       <eviction wakeUpInterval="10000">
      
       <default algorithmClass="org.jboss.cache.eviction.LRUAlgorithm" eventQueueSize="200000">
       <property name="maxNodes" value="5000" />
       <property name="timeToLive" value="1000000" />
       </default>
      
       <region name="/users">
       <property name="maxNodes" value="5" />
       <property name="timeToLive" value="1000" />
       </region>
      
       </eviction>
      </jbosscache>


      Thank you all in advance. Greetings,


      Andres Pachon (andresp21@gmail.com)

        • 1. Re: Eviction problems: Thread executing before specified tim
          Galder Zamarreño Master

          andresp21, the 1st the eviction thread is executed, it's executed at wakeUpInterval/2, the rest of the times at wakeUpInterval.

          With regards to the wrong nodes being removed, could you show us the client code you're executing and explain which of the nodes you're putting are you seeing being evicted?

          • 2. Re: Eviction problems: Thread executing before specified tim
            Andres Pachon Newbie

            Hi Galder,

            First of all, thank you for your response.

            1) Client code

            public static void main(String[] args) throws Exception {
            
             CacheFactory factory = new DefaultCacheFactory();
             Cache cache = factory.createCache("cache-config.xml");
             Node rootNode = cache.getRoot();
            
             //1. Add 5 objects to cache:
            
             for(int i=1;i<=5;i++){
            
             Fqn fqn = Fqn.fromString("/user/"+i);
             Node node = rootNode.addChild(fqn);
             node.put("id", ""+i);
             }
            
             while(true){
            
             //2. Query the first 3 objects so that they become the most recently used. This way the remaining 2 nodes would be evicted
             for(int i=1;i<=3;i++){
             Fqn fqn = Fqn.fromString("/user/"+i);
             Node node = cache.getNode(fqn);
             }
            
             //3. Try to put 2 new.
             for(int i=0;i<2;i++){
             double random = Math.random();
             Fqn fqn = Fqn.fromString("/user/"+random);
             Node node = rootNode.addChild(fqn);
             node.put("id", "" + random);
             }
            
             //4. Print cache:
             System.out.println(cache.getChildrenNames("/user/"));
            
            
             //5. Sleep for some secs to visualize console
             Thread.currentThread().sleep(2000);
            
             }


            2) xml config

            <?xml version="1.0" encoding="UTF-8"?>
            <jbosscache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:jboss:jbosscache-core:config:3.1">
            
            <transaction transactionManagerLookupClass="org.jboss.cache.transaction.GenericTransactionManagerLookup"/>
            
             <eviction wakeUpInterval="
            10000
            ">
            
             <default algorithmClass="org.jboss.cache.eviction.
            LRUAlgorithm
            " eventQueueSize="200000">
             <property name="maxNodes" value="5000" />
             <property name="timeToLive" value="1000000" />
             </default>
            
             <region name="/user">
             <property name="maxNodes" value="5" />
             <property name="timeToLive" value="1000" />
             </region>
            
             </eviction>
            </jbosscache>


            3) Expected behavior:

            Given that the specified max number of nodes equals 5, and only 3 of them are queried, I expect that the remaining 2 (the ones that are not queried) are evicted (given the LRU policy). However, I've identified the following problems when looking into the console:

            1) 2 of the 3 queried nodes are evicted (this means, 2 of the 3 most recent nodes were evicted)
            2) The cache size exceeds the specified constraint (it has more than 5 elements after several iterations of the cycle)
            3) The eviction therad is always executed every wakeUpInterval/2


            Thank you very much for your time, I'll be eagerly waiting for your response.


            Greetings,

            Andres Pachon




            • 3. Re: Eviction problems: Thread executing before specified tim
              Galder Zamarreño Master

              Hi, apologies for the delay.

              Re 1: The problem resides in your test. Whenever you call the following code, you're traversing /user FQN and so it's the same as you were doing cache.get("/user/1"), cache.get("/user/2"), cache.get("/user/3"), cache.get("/user/4")...etc. So, 4 and 5 are always used and since this is the last call of the loop before the sleep, they're the most LRU and so data added in 3 will be evicted. So, the behaivour you're seeing is correct.

              System.out.println(cache.getChildrenNames("/user/"));


              Re 2: The size is exceeded for only a brief period of time. When eviction kicks in, it's reduced back to 5. Obviously, to see this number exactly, you'd need to print the contents as soon as the eviction round finished and before you add any new data!

              Re 3: Just run your test and verified that eviction gets, first time run in 5 seconds and afterwards every 10 seconds:

              grep -nH -e "EvictionTimerTask" jbosscache.log
              jbosscache.log:242:2009-09-15 18:20:56,127 520 TRACE [org.jboss.cache.eviction.EvictionTimerTask] (main:) Creating a new eviction listener with wakeupInterval millis set at 10000
              jbosscache.log:1509:2009-09-15 18:21:01,155 5548 TRACE [org.jboss.cache.eviction.EvictionTimerTask] (EvictionTimer-0:) Processing eviction regions [/, /user]
              jbosscache.log:3168:2009-09-15 18:21:11,243 15636 TRACE [org.jboss.cache.eviction.EvictionTimerTask] (EvictionTimer-0:) Processing eviction regions [/, /user]
              jbosscache.log:4908:2009-09-15 18:21:21,295 25688 TRACE [org.jboss.cache.eviction.EvictionTimerTask] (EvictionTimer-0:) Processing eviction regions [/, /user]