-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 posts ] 
Author Message
 Post subject: EJB3 BUG with EJBQL
PostPosted: Wed Feb 08, 2006 4:50 pm 
Regular
Regular

Joined: Tue Nov 08, 2005 1:30 pm
Posts: 50
Hi
IT seems its having problem with EJB3 Session Beans

If its not the right place to post then let me know where to post..


Here is the Issue...

Session Bean Contains FindbyName Method..

that FindbyName

IMPORTANT HERE....

Clent

Sessionbean.findbyName method doesnot contain loops coz ur looping outside..i.e looping in cleint..
Code:
for (int i = 0; i < 50000; i += 2)
sessionbean.findbyName();




then it does really good

But when i do loop INSIDE SESSION BEAN

Like BELOW EXAMPE
in SESSIONBEAN.findbyName method
Code:

try {
            System.out.println("its in  query");
            Query query1;
                            System.out.println("elapsed time" + elapsedTime);
            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();
             

            }




This time i Get timming is too late.. if u want i can post the code also.. with all methods...




please let me know why i am getting that...


SEEMS ISSUE IN EJB3..



Thanks
Nag[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 09, 2006 9:45 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I don't understand you problem, but if you try to measure an avefragte time with the code shown, then forget about it:
- this is instantaneous time
- the VM might not be precise enough for 0-10ms measurements
- microbenchmarks does not play nice with JIT

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 09, 2006 1:13 pm 
Regular
Regular

Joined: Tue Nov 08, 2005 1:30 pm
Posts: 50
Hey,
Good to See your reply.. I guess Its the problem with LEVEL1 Cache.. Ok i know u dont get exact time when u use system.currenttimeInMillis.. But try to see the issue not the timmer issue..


Observe the loop inside the bean and loop out side the bean..

I really appreciate if u try to look into the issue instead of looking in other issues(like timmer and all)


If u want i can post the code..

SessionBean InterFace
Code:

@Remote
public interface SessionBeanInterface {

   public void insertname(String name, int id);
    public void loopInsideTheBean();
    public void loopOutsideTheBean(int i);
}



SessiobBean Impl

Code:
public @Stateless
class SessionBeanImpl implements SessionBeanInterface {

    @PersistenceContext(unitName = "persisa")
    public EntityManager em;
    long elapsedTime = 0;

    public void insertname(String name, int id) {
        try {

            EntitBean eBean = new EntitBean();
            System.out.println("Made it to server");
            for (int i = 4000; i < 50000; i++) {
                System.out.println("inserting");
                eBean.setId(i);
                eBean.setName(name);
                em.merge(eBean);
            }
            System.out.println("Server scred me");
        } catch (Exception e) {
            System.out.println("Server scred me2");
            e.printStackTrace();
        }

    }

    public void loopInsideTheBean() {
       
        int orderId;
        List orders = null;
        long timer1;
        long timer2;
     

        try {
            System.out.println("its in  query");
            Query query1;
            //Query query1 = em
            //        .createQuery(" from EntitBean po where po.id = :orderId");
     
            System.out.println("elapsed time" + elapsedTime);
            for (int i = 0; i < 50000; i += 2) {

                //query1.setParameter("orderId", i);
                query1 = em.createQuery(" from EntitBean po where po.id = " + i);
                timer1 = System.currentTimeMillis();

                orders = query1.getResultList();
                timer2 = System.currentTimeMillis();
                elapsedTime += (timer2 - timer1);
                // System.out.println("elapsed time out side is "+elapsedTime+"
                // i is "+i);
                if (i % 200 == 0) {
                    System.out.println("elapsed time for 100   " + elapsedTime);
                    elapsedTime = 0;
                }
                orders.clear();
             

            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            elapsedTime = 0;
        }

    }

    public void loopOutsideTheBean(int i) {
       
        List orders = null;
        long timer1;
        long timer2;
       

        try {
           // System.out.println("its in  query");
            Query query1 = em
                    .createQuery(" from EntitBean po where po.id = :orderId");
          // System.out.println("elapsed time" + elapsedTime);

            query1.setParameter("orderId", i);
            timer1 = System.currentTimeMillis();

            orders = query1.getResultList();
            timer2 = System.currentTimeMillis();
            elapsedTime += (timer2 - timer1);
            // System.out.println("elapsed time out side is "+elapsedTime+" i is
            // "+i);
            if (i % 200 == 0) {
                System.out.println("elapsed time for 100  " + elapsedTime);
                elapsedTime = 0;
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}



Entity Bean

Code:
@Entity
@Table(name = "ENTITY_BE1")
public class EntitBean {
   private int id;

   private String name;

   @Id(generate = GeneratorType.NONE)
   @Column(name="IDd")
   public int getId() {
      return id;
   }

   public void setId(int id) {
      this.id = id;
   }
   
   @Column(name="Name")
   public String getName() {
      return name;
   }

   public void setName(String name) {
      this.name = name;
   }


}





Stand Alone Client...
Code:
public class HellClient {

    public static void main(String[] args) {
        try {
            InitialContext ic = new InitialContext();
            System.out.println("after context");
            SessionBeanInterface sessionBeanObj = (SessionBeanInterface) ic
                    .lookup(SessionBeanInterface.class.getName());
         
            // sessionBeanObj.insertname("abc", 12);
            sessionBeanObj.loopInsideTheBean();
           /* for (int i = 0; i < 50000; i++) {
                sessionBeanObj.loopOutsideTheBean(i);
            }*/
        } catch (Exception e) {
            System.out.println("ssssss" + e.getMessage());
            e.printStackTrace();
        }

    }

}



Thanks
Nag


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 10, 2006 7:01 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
But what is your problem. I see no stacktrace, no description...

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 10, 2006 1:08 pm 
Regular
Regular

Joined: Tue Nov 08, 2005 1:30 pm
Posts: 50
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:

Code:

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
Code:

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


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 10, 2006 1:08 pm 
Regular
Regular

Joined: Tue Nov 08, 2005 1:30 pm
Posts: 50
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:

Code:

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
Code:

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


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 12, 2006 10:25 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
http://www.hibernate.org/hib_docs/v3/reference/en/html_single/#transactions-basics-issues

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 13, 2006 12:52 am 
Regular
Regular

Joined: Tue Nov 08, 2005 1:30 pm
Posts: 50
Hi,
Thanks For the anwser. I understand in Hibernate.. But I am still confused with how to do in EJB3.. I am using CMT, Stateless bean.

I am just using entitymanger.getquery();

Do u have any idea.. Do u know which doc i need to refer..
Thanks
nag


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 16, 2006 8:57 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
If I remember I've described the entity manager lifecycle integration regarding EJB3 container integration.
http://www.hibernate.org/hib_docs/entitymanager/reference/en/html_single/

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.