-->
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.  [ 3 posts ] 
Author Message
 Post subject: Performance and Postgresql
PostPosted: Wed Oct 27, 2004 7:38 pm 
Newbie

Joined: Mon Oct 25, 2004 4:34 pm
Posts: 6
Hibernate version: 2.1.6

Code between sessionFactory.openSession() and session.close():
Code:
    private static void runHQL(int runs) {
        Session s = null;
        LongType lt = new LongType();
        String hql_ab_string = "from AccountsBasics ab where ab.Id = ?";
        for (int r = 0; r < runs; r++) {
           for (long i = 58; i< 64 ; i++) {
               try {
                   s = HibernateUtil.currentSession();
                   s.iterate(hql_ab_string, new Long(i), lt).next();
                   HibernateUtil.closeSession();
               } catch (HibernateException he) {
                   he.printStackTrace();
               }
           }
        }
    }

    private static void runSessionLoad(int runs) {
        Class clazz = AccountsBasics.class;
        Session s = null;
        for (int r = 0; r < runs; r++) {
           for (long i = 58; i< 64 ; i++) {
               try {
                   s = HibernateUtil.currentSession();
                   s.load(clazz, new Long(i));
                   HibernateUtil.closeSession();
               } catch (HibernateException he) {
                   he.printStackTrace();
               }
           }
        }
    }

    private static void runSQL(int runs) {
        Connection conn = null;
        Statement c_stmt = null;
        for (int r = 0; r < runs; r++) {
           for (long i = 58; i< 64 ; i++) {
               try {
                    conn = ds.getConnection();
                    c_stmt = conn.createStatement();
                   createAB(c_stmt.executeQuery("Select * from Accounts_Basics where id = "+ i));
                   conn.close();
               } catch (SQLException se) {
                   se.printStackTrace();
               }
           }
        }
    }


Name and version of the database you are using:
PostgreSQL 7.4.2

The generated SQL (show_sql=true):

runHQL generates:
Hibernate: select accountsba0_.id as x0_0_ from accounts_basics accountsba0_ where (accountsba0_.id=? )
Hibernate: select accountsba0_.id as id0_, accountsba0_.handle as handle0_, accountsba0_.password_question_answer as password3_0_, accountsba0_.starts as starts0_, accountsba0_.password_hash as password5_0_, accountsba0_.birthdate as birthdate0_, accountsba0_.sex as sex0_, accountsba0_.country as country0_, accountsba0_.email as email0_, accountsba0_.ends as ends0_, accountsba0_.zip as zip0_, accountsba0_.auth_status_id as auth_st12_0_, accountsba0_.password_question_id as passwor13_0_, accountsba0_.language_id as languag14_0_ from accounts_basics accountsba0_ where accountsba0_.id=?

runSessionLoad generates:
Hibernate: select accountsba0_.id as id0_, accountsba0_.handle as handle0_, accountsba0_.password_question_answer as password3_0_, accountsba0_.starts as starts0_, accountsba0_.password_hash as password5_0_, accountsba0_.birthdate as birthdate0_, accountsba0_.sex as sex0_, accountsba0_.country as country0_, accountsba0_.email as email0_, accountsba0_.ends as ends0_, accountsba0_.zip as zip0_, accountsba0_.auth_status_id as auth_st12_0_, accountsba0_.password_question_id as passwor13_0_, accountsba0_.language_id as languag14_0_ from accounts_basics accountsba0_ where accountsba0_.id=?

runSQL generates:
Select * from Accounts_Basics where id = i
---------------------------

on test runs with 1000 iterations, runHQL takes 16 seconds, runSessionLoad takes 15 seconds, and runSQL takes 7.5 seconds. 10000 and 20000 runs have similar results. As can be seen from the show_sql output, the relationships of Accounts_Basics are not followed (all the many to ones are set to lazy)

Obviously, I'm doing something wrong, but what is it? (changing iterate to find does not help, it generates the same SQL as session.load, and takes the same time.)

and no, I'm not cheating by not creating the object in the SQL test. create AB news the object, does a rs.next() and does 14 calls of the form:
Code:
ab.setXYZ(rs.getXYZTYPE("XYZ"))


thanks in advance for any help.
Jeff


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 28, 2004 3:04 pm 
Newbie

Joined: Mon Oct 25, 2004 4:34 pm
Posts: 6
Oops, I messed up, sessionLoad takes 15 seconds, HQL takes 20. when I change the HQL from "iterate()" to "find()", the extra select goes away and the HQL takes 16 seconds. Still, that is twice the time of the straight SQL.

Help, anyone?

Jeff


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 28, 2004 4:19 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
all topics about performance finished by the same conclusion, please search the forum

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.