5 Replies Latest reply on Dec 18, 2009 4:00 AM by Galder Zamarreño

    Memory usage in simple pojocache test app

    James Lotery Newbie

      Hi,

      I am currently trying to evaluate Pojo Cache and to do so I wrote a simple test based on what I had read in the user guide.

      Quite simply all my test program does is create a bunch of objects x times adding them each time to the cache and then removing from the cache using the detach method.

      This is repeated several times and then the program stays in memory so that I can observe the memory.

      To my suprise in spite of removing the objects from the cache and removing them from memory, the memory in app grows and grows and grows and never comes down.

      Initially I when I ran this I was using the latest Sun JVM with which I was getting an out of memory error, so following some advise I saw in a newsgroup I switched to the JRockit JVM which solved the OOM error, but my memory is still growing and never coming down.

      Code is below, but can someone tell me if this is normal behaviour of the PojoCache or if I am doing something wrong. Also I'm using the configuration files supplied with distribution in the test directory.

      Here's the code:


      public class PojoCacheTest {

      String configFile = "conf/replSync-service.xml";

      public void test(){
      PojoCache cache = PojoCacheFactory.createCache(configFile);
      cache.create();

      try {
      Thread.sleep(1000 * 10);
      } catch (InterruptedException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      }

      System.out.println("starting to create objects");

      for (int i = 0; i <10000; i++){
      cache.attach("/pojo/testobjects/object"+i, new TestPojoObject());
      System.out.println ("/pojo/testobjects/object"+i);
      }

      for (int i = 0; i <10000; i++){
      cache.detach("/pojo/testobjects/object"+i);
      System.out.println ("/pojo/testobjects/object"+i);
      }

      for (int i = 10000; i <20000; i++){
      cache.attach("/pojo/testobjects/object"+i, new TestPojoObject());
      System.out.println ("/pojo/testobjects/object"+i);
      }

      for (int i = 10000; i <20000; i++){
      cache.detach("/pojo/testobjects/object"+i);
      System.out.println ("/pojo/testobjects/object"+i);
      }

      for (int i = 20000; i <30000; i++){
      cache.attach("/pojo/testobjects/object"+i, new TestPojoObject());
      System.out.println ("/pojo/testobjects/object"+i);
      }

      for (int i = 20000; i <30000; i++){
      cache.detach("/pojo/testobjects/object"+i);
      System.out.println ("/pojo/testobjects/object"+i);
      }

      for (int i = 30000; i <40000; i++){
      cache.attach("/pojo/testobjects/object"+i, new TestPojoObject());
      System.out.println ("/pojo/testobjects/object"+i);
      }

      for (int i = 30000; i <40000; i++){
      cache.detach("/pojo/testobjects/object"+i);
      System.out.println ("/pojo/testobjects/object"+i);
      }

      for (int i = 40000; i <50000; i++){
      cache.attach("/pojo/testobjects/object"+i, new TestPojoObject());
      System.out.println ("/pojo/testobjects/object"+i);
      }

      for (int i = 40000; i <50000; i++){
      cache.detach("/pojo/testobjects/object"+i);
      System.out.println ("/pojo/testobjects/object"+i);
      }

      for (int i = 50000; i <60000; i++){
      cache.attach("/pojo/testobjects/object"+i, new TestPojoObject());
      System.out.println ("/pojo/testobjects/object"+i);
      }

      for (int i = 50000; i <60000; i++){
      cache.detach("/pojo/testobjects/object"+i);
      System.out.println ("/pojo/testobjects/object"+i);
      }

      for (int i = 60000; i <70000; i++){
      cache.attach("/pojo/testobjects/object"+i, new TestPojoObject());
      System.out.println ("/pojo/testobjects/object"+i);
      }

      for (int i = 60000; i <70000; i++){
      cache.detach("/pojo/testobjects/object"+i);
      System.out.println ("/pojo/testobjects/object"+i);
      }

      for (int i = 70000; i <80000; i++){
      cache.attach("/pojo/testobjects/object"+i, new TestPojoObject());
      System.out.println ("/pojo/testobjects/object"+i);
      }

      for (int i = 70000; i <80000; i++){
      cache.detach("/pojo/testobjects/object"+i);
      System.out.println ("/pojo/testobjects/object"+i);
      }


      for (int i = 80000; i <90000; i++){
      cache.attach("/pojo/testobjects/object"+i, new TestPojoObject());
      System.out.println ("/pojo/testobjects/object"+i);
      }

      for (int i = 80000; i <90000; i++){
      cache.detach("/pojo/testobjects/object"+i);
      System.out.println ("/pojo/testobjects/object"+i);
      }

      for (int i = 90000; i <100000; i++){
      cache.attach("/pojo/testobjects/object"+i, new TestPojoObject());
      System.out.println ("/pojo/testobjects/object"+i);
      }

      for (int i = 90000; i <100000; i++){
      cache.detach("/pojo/testobjects/object"+i);
      System.out.println ("/pojo/testobjects/object"+i);
      }

      for (int i = 100000; i <110000; i++){
      cache.attach("/pojo/testobjects/object"+i, new TestPojoObject());
      System.out.println ("/pojo/testobjects/object"+i);
      }

      for (int i = 100000; i <110000; i++){
      cache.detach("/pojo/testobjects/object"+i);
      System.out.println ("/pojo/testobjects/object"+i);
      }
      System.out.println("finished object clearage");

      cache.destroy();
      cache.stop();

      }

      public static void main(String args[]){
      PojoCacheTest pct = new PojoCacheTest();
      pct.test();

      while (true){

      }
      }

      Thanks in advance for any help

      James