9 Replies Latest reply on Mar 24, 2009 10:31 AM by angusm

    LRUPolicy eviction policy

    lovelyliatroim

      Just something i found confusing when reading the documents.

      In the documentation it states maxNodes as follows for LRUPolicy




      # maxNodes - This is the maximum number of nodes allowed in this region. 0 denotes no limit.


      So if i have something like configured


      <region name="evictiontest/LRU" policyClass="org.jboss.cache.eviction.LRUPolicy">
       <attribute name="maxNodes">3</attribute>
       <attribute name="timeToLiveSeconds">0</attribute>
       <attribute name="maxAgeSeconds">10</attribute>
       </region>
      


      Now if I add 10 elements like so to the cache
      evictiontest/LRU/a/b/c1(1)
      evictiontest/LRU/a/b/c2(1)
      evictiontest/LRU/a/b/c3(1)
      evictiontest/LRU/a/b/c4(1)

      etc

      After eviction i would have expected to see just one record in the cache
      evictiontest/LRU/a/b/c*(1)

      however I see 3 records
      evictiontest/LRU/a/b/c1(1)
      evictiontest/LRU/a/b/c2(1)
      evictiontest/LRU/a/b/c3(1)

      So when i have set maxNodes to 3, does it actually mean 3 nodes which have a data item attached to the node?? I was thinking it was 3 nodes in total allowed from the region base hence why i thought one record would be allowed.

      So breakdown of
      evictiontest/LRU/a/b/c1(1)

      a = 1 node
      b = 2 nodes
      c1 = 3 nodes so no more nodes should be allowed in this region!!


      I have done the test on it and looks to me like its based on nodes with data attached, could someone just confirm this for me on how it works.

      Thanks,
      LL



        • 1. Re: LRUPolicy eviction policy
          lovelyliatroim

          Also documentation for this


          # timeToLiveSeconds - The amount of time a node is not written to or read (in seconds) before the node is swept away. 0 denotes no limit.


          If you leave it out, you get an exception like so
          
          org.jboss.cache.config.ConfigurationException: timeToLiveSeconds must be configured to a value greater than or equal to 0
           at org.jboss.cache.eviction.LRUConfiguration.validate(LRUConfiguration.java:85)
           at org.jboss.cache.factories.XmlConfigurationParser.parseEvictionPolicyConfig(XmlConfigurationParser.java:616)
          
          


          Docs should possibly state that this is mandatory or let the default value for this be 0 when nothing configured for it.

          Just passing on some thoughts on it.

          Cheers,
          LL


          • 2. Re: LRUPolicy eviction policy
            lovelyliatroim

            Just seen this in the documents


            Q. I have set up an eviction region but none of the nodes in that region get evicted.



            Make sure that the region starts with the / character, i.e.

            <region name="/org/jboss/data" ...



            I see that i was missng a "/" at the start in my original post, doesnt make a difference though. After first eviction sweep 3 records are still present.

            • 3. Re: LRUPolicy eviction policy
              manik

               

              "lovelyliatroim" wrote:

              I have done the test on it and looks to me like its based on nodes with data attached, could someone just confirm this for me on how it works.


              Have you marked any of these as resident?

              • 4. Re: LRUPolicy eviction policy
                lovelyliatroim

                 


                Have you marked any of these as resident?

                No none marked as resident!!

                Will dig out my test case and post, not sure the config is right because i was playing around with different scenarios, will set up properly tomorrow and post it.

                • 5. Re: LRUPolicy eviction policy
                  lovelyliatroim

                  So here is the config for the test

                   <region name="/evictiontest/LRU" policyClass="org.jboss.cache.eviction.LRUPolicy">
                   <attribute name="maxNodes">3</attribute>
                   <attribute name="timeToLiveSeconds">30</attribute>
                   <attribute name="maxAgeSeconds">30</attribute>
                   </region>
                  
                  



                  My sample test case
                  public void evictionTest(String configPath) throws Exception{
                   CacheFactory factory = DefaultCacheFactory.getInstance();
                   Cache cache = factory.createCache(configPath);
                   CacheJmxWrapperMBean wrapper = new CacheJmxWrapper(cache);
                   wrapper.create();
                   wrapper.start();
                   System.out.println("Cache created");
                  
                   String lruPath="/evictiontest/LRU/a/b/c";
                   Fqn lruFQN =Fqn.fromString(lruPath);
                  
                   String expPath="/evictiontest/EXP/a/b/c";
                   Fqn expFQN =Fqn.fromString(expPath);
                  
                   String key ="data";
                   HashMap testData = new HashMap();
                   testData.put("Client", "Bond,James");
                  
                   cache.put(lruFQN,key, testData);
                  
                   HashMap val = (HashMap)cache.get(lruFQN, key);
                   System.out.println("Value taken from hash "+val.toString());
                  
                   //Test Max Nodes attribute now and how that works
                   for(int i = 0; i < 10 ;i ++){
                   lruFQN =Fqn.fromString(lruPath+i);
                   cache.put(lruFQN,key, testData);
                   }
                   System.out.println("Added more nodes than allowed to region " + wrapper.printCacheDetails());
                  
                   int counter = 0;
                   while(true){
                   counter = counter + 10;
                   Thread.currentThread().sleep(10000);
                   System.out.println("Slept "+counter +" secs " + wrapper.printCacheDetails());
                  
                   }
                  
                  



                  Output that i see



                  Cache created
                  Value taken from hash {Client=Bond,James}
                  Added more nodes than allowed to region / null
                   /evictiontest null
                   /LRU null
                   /a null
                   /b null
                   /c5 {data={Client=Bond,James}}
                   /c6 {data={Client=Bond,James}}
                   /c8 {data={Client=Bond,James}}
                   /c {data={Client=Bond,James}}
                   /c7 {data={Client=Bond,James}}
                   /c9 {data={Client=Bond,James}}
                   /c2 {data={Client=Bond,James}}
                   /c0 {data={Client=Bond,James}}
                   /c1 {data={Client=Bond,James}}
                   /c4 {data={Client=Bond,James}}
                   /c3 {data={Client=Bond,James}}
                  
                  Slept 10 secs / null
                   /evictiontest null
                   /LRU null
                   /a null
                   /b null
                   /c8 {data={Client=Bond,James}}
                   /c7 {data={Client=Bond,James}}
                   /c9 {data={Client=Bond,James}}
                  
                  Slept 20 secs / null
                   /evictiontest null
                   /LRU null
                   /a null
                   /b null
                   /c8 {data={Client=Bond,James}}
                   /c7 {data={Client=Bond,James}}
                   /c9 {data={Client=Bond,James}}
                  
                  Slept 30 secs / null
                   /evictiontest null
                   /LRU null
                   /a null
                   /b null
                   /c8 {data={Client=Bond,James}}
                   /c7 {data={Client=Bond,James}}
                   /c9 {data={Client=Bond,James}}
                  
                  Slept 40 secs / null
                   /evictiontest null
                   /LRU null
                   /a null
                   /b null
                  
                  


                  Eviction timer thread runs every 3 seconds. So back to the original question, how does maxNodes work?? Its configured as 3, so is that 3 nodes with data below the region or is it 3 nodes regardless of data below the region?? It looks to me like it is nodes with data!! Is this the expected behaviour??

                  The remaining 3 records get evicted after they have lived their life expectancy of 30 seconds.

                  By the way this last test was carried out with 3.x version but the original test was done with the 2.x version.


                  • 6. Re: LRUPolicy eviction policy
                    manik

                    I'll let Mircea answer, he's the guy who added the resident node feature. :-)

                    • 7. Re: LRUPolicy eviction policy
                      mircea.markus

                       

                      Eviction timer thread runs every 3 seconds. So back to the original question, how does maxNodes work??

                      The general rule is that implicitly created nodes are not being counted for eviction. They are not structural nodes neither (e.g. if you add something to them they will be considered for eviction).


                      • 8. Re: LRUPolicy eviction policy
                        lovelyliatroim

                         


                        The general rule is that implicitly created nodes are not being counted for eviction. They are not structural nodes neither (e.g. if you add something to them they will be considered for eviction).


                        Hi Mircea,
                        Ok I need to brush up on my jboss cache terminology, so correct me if im wrong

                        Structural Nodes are what you would call resident nodes??? So in this example "/evictiontest/LRU" would be a structural node.

                        Implicitly created nodes are nodes which are created to make up the tree path to get to the data node so in this example "/a/b" would be implicit nodes.


                        So in lay man terms, if a node in a region has a data item attached, the maxNodes counter goes up one, if not then the counter stays the same!!

                        Thanks for your time Mircea,
                        LL





                        • 9. Re: LRUPolicy eviction policy

                          Mircea (or other),
                          Is it possible to configure implicitly created nodes so they are evicted?
                          I have a cache (JBC 303) which will have 100,000 entries, and a depth of 5. So that is, potentially, 400,000 implicitly created nodes hanging around indefinitely (if I have correctly understood).
                          Thanks, Angus