3 Replies Latest reply on Feb 12, 2006 10:00 AM by epbernard

    Problem With EJB or JBOSS CACHE..seems L1 Cache Problem

    kasinath

      Posted: Fri Feb 10, 2006 5:08 pm Post subject:

      In the first case, we are looking up 5000 entities by looping on the client, meaning that we start a new session 5000 times.

      In the second case, the lookup loop has been moved into the session bean. Under the second scenario, all of these 5000 lookups are performed within the context of the same session.

      Against all logic, the second scenario performs much worse than the first one. The time to process each record appears to increase geometrically, until it litterally gets to a crawl.

      Also, the second scenario generates massive paging to disk (which does not make any sense, since we are only performing lookups).

      We were wondering if this was not a level-2 cache issue, so we totally disabled the level 2 cache by switching to the NoCacheProvider in our persistence.properties file, and this did not help the performance issue.

      Consequenty, we are now wondering if the level-1 cache is not trying to page to disk !!!

      (I know this sounds crazy, but remember that all we are doing are lookups, and that looking up these 5000 records takes about 20 times longer when looping within the session bean).



      DETAILS LOOK BELOW


      Lookin the code what my loopInsideTheBean, loopOutsideTheBean methods does...

      CASE 1:

      When i loop in client(out side the bean..means calling loopOutsideTheBean method from client ) then i am getting with out any time difference().. all the records comming pretty fast..

      ex: time for 1st hundread 200
      2nd 100 is 210
      3rd 100 is 200
      4th 100 is 190

      almost all the records comming in same time...



      CASE 2:

      When I loop 5000 times inside the BEAN then for each 100 records time is increasing..
      example first 100 i am getting in 200ms
      2nd 100 record in 230ms
      4th 100 in 300


      10 th 100 in 1000ms..
      ...its keeps on increasing...

      can you please look into the issue..

      It seems its a problem with level1 cache.. in the CASE1...




      U can look at my code in my previous reply...

      Well i am writting small Code here agin for both CASEs.

      CASE1:
      
      
      
      Clent:
      for(int i=0;i<5000;i++){
      loopOutsideTheBean(i)
      }
      
      
      Bean:
      
      loopOutsideTheBean(int i){
      
       query1 = em.createQuery(" from EntitBean po where po.id = " + i);
       timer1 = System.currentTimeMillis();
      
       orders = query1.getResultList();
       timer2 = System.currentTimeMillis();
       elapsedTime += (timer2 - timer1);
       if (i % 200 == 0) {
       System.out.println("elapsed time for 100 " + elapsedTime);
       elapsedTime = 0;
       }
       orders.clear();
       }
      
      
      
      




      Code for CASE2 Looks Like

      for (int i = 0; i < 50000; i += 2) {
      
       query1 = em.createQuery(" from EntitBean po where po.id = " + i);
       timer1 = System.currentTimeMillis();
      
       orders = query1.getResultList();
       timer2 = System.currentTimeMillis();
       elapsedTime += (timer2 - timer1);
       if (i % 200 == 0) {
       System.out.println("elapsed time for 100 " + elapsedTime);
       elapsedTime = 0;
       }
       orders.clear();
      
      }
      
      
      
      
      
      

      ITs not a timer issue, I am sure about it.. coz just look abt the examples i provide for both cases..



      My question is why time is increasing in CASE1.. and not in CASE2?
      IS there any Problem with Session Level Cache(level1 cache)?




      Thanks
      Nag