4 Replies Latest reply on Nov 29, 2011 5:31 PM by sathish_06

    JBoss Cache - Memory Leak when many Fqn/nodes added in Cache

    sathish_06

      All - Iam observing OOM in JBoss Cache, with below mentioned scenario. Would like to get  suggestions/help on the approach that iam doing  to over come the situation is correct or not.  Here is the details on the problem,

       

      Problem:- JBoss Cache - Memory Leak when many Fqn/nodes added in Cache using TreeCache.put() API

       

      Explanation of the problem:-  When adding new data in cache with  new node in the tree, its causing memory leak.

       

      Environment/Config settings:-

       

      JBoss Cache Version:-JBossCache 1.2.4.SP2[ $Id: Version.java,v 1.5.2.1.4.3 2006/02/15 05:08:06 bstansberry Exp $]\

      CacheMode:LOCAL

      EvictionPolicy: LRUPolicy

      Test Cache region - /testRegionX definition:-

       

      <region name="/testRegionX">
          <attribute name="maxNodes">1000</attribute>
          <attribute name="timeToLiveSeconds">30</attribute>
          <!-- Maximum time an object is kept in cache regardless of idle time -->
          <attribute name="maxAgeSeconds">30</attribute>
      </region> 
      

       

      In the test code, start adding new objects in the cache(treeCache.put(identifier, key , vo)) with different FQN/tree node,  as shown below.

       

      /testRegionX/a/b/         k1, v1

      /testRegionX/a1/b1/       k2, v2

      /testRegionX/a12b2/       k2, v3

      .....

       

      Snippet of the test code,

       

      TreeCache treeCache;
      try {
          treeCache = new TreeCache();
          treeCache.setCacheMode(TreeCache.LOCAL);
          System.out.println("JBoss Cache Version:-" + treeCache.getVersion());
      
          PropertyConfigurator config = new PropertyConfigurator();  
          config.configure(treeCache, "TreeCache.xml");    
          treeCache.startService();            
          String identifier_prefix = "/testRegionX";
          String key_prefix = "key_01_";
      
          for(long i=0;;i++)
          {
              String key = key_prefix + i;
              String identifier = identifier_prefix + "/" + i + "/data/";
              //String identifier = identifier_prefix;
              System.out.println("Identifer = " + identifier);
      
              DummyVO vo  = new DummyVO();
              System.out.println("Adding[Id=new node, Key=unique] - Key - " + key);
              treeCache.put(identifier, key , vo);
      
              //access the data from cache
              treeCache.get(identifier, key);
      
                   //dont call remove 
              //treeCache.remove(identifier, key);
              //System.out.println("cache.remove called");
          }
      
          //treeCache.stopService();
      } catch (Exception e) {
          e.printStackTrace();
      }
      

       

      Refer attached zip file contains complete Tree cache configuration(TreeCache.xml) and test code. Just point the jboss library location in the ant.properits file to run the test code.

       

      Note that i dont call the tree.remove() to remove the cache data, instead let the Cache manager evict the object once it gets expired(configured expiry time to 30 seconds.).

       

      Ran test with default JVM heap size, and reunning out of memory in the 50K iteration. Took JMap histo and noticed that below 2 objects are not releasing, Attached  histo in text file.

       

      C:\Documents and Settings\skandasa>jmap -histo:live   4508

       

       num     #instances         #bytes  class name
      ----------------------------------------------
         1:        107609       16019856  [LEDU.oswego.cs.dl.util.concurrent.ConcurrentReaderHashMap$Entry;
         3:        107609        6026104  EDU.oswego.cs.dl.util.concurrent.ConcurrentReaderHashMap
      

       

      When I start adding new objects in the cache(treeCache.put(identifier, key , vo)) in the same tree node ('/testRegionX' ie., not creating new nodes in the tree, as shown below) then not observing this OOM problem. 
      
      
      /testRegionX/       k1, v1
      /testRegionX/       k2, v2
      /testRegionX/       k2, v3
      .....
      
      In other words, if i simply store data in cache as a Hashmap, without creating many tree nodes, then not observing OOM.
      
      
      

       

      Any thoughts on this behaviour of the JBoss cache ? How can i get control over the OOM problem when adding new nodes in the tree cache ?

       

      Please advice!

       

       

      Thanks,

      Sathish