-->
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: Select Performance with Postgres
PostPosted: Sat Mar 04, 2006 9:59 pm 
Beginner
Beginner

Joined: Sat Jan 01, 2005 12:18 pm
Posts: 23
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.0.5

Database: Postgres 8.1


I have got a very strange performance problem with Hibernate.

Lets assume I have got a List with a bunch of Ids and want to query for their objects persited in my database.

Way 1 - The slow one:

Code:
Iterator it= idList.iterator();
  while (it.hasNext()) {
     Object obj = xyzDAO.getXyzById((Long)it.next());
  }


This one creates several select statements with a response time of approx. 15ms to 30ms

Select statement from Hibernate looks like this:
Code:
select * from xyz where id = ?
..
..




Way 2 - The fast one:

Code:
List obj = xyzDAO.getXyzByListOfIds(idList);


Here I create a query putting together an OR combined list and get back a List with my result objects.

The one Select statement from Hibernate looks like this:
Code:
select * from xyz where id = ? or id = ? or ....


This statement has a response time of approx. 15ms to 30ms. So this one statement delivers me the desired result in the time that one of the statements above from Way 1 needs.

If I have got 1000 ids to retrieve it would take in worst case 30ms*1000 to get them using the Way 1 and with Way 2 only 30ms.


Can anyone explain this performance problem?!?







[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 05, 2006 3:42 am 
Regular
Regular

Joined: Wed Feb 08, 2006 3:59 pm
Posts: 75
Everytime Hibernate (or any JDBC based application) sends a query to a database, you get an huge overhead : you've got to create the query, serialize it to TCP/IP, chat a bit in JDBC with the DB, wait for a response, switch to the DB process, get the query, parse it, execute it, send the result to TCP/IP, switch to the Java process, etc.
Usually the bottleneck is the TCP/IP, so for a query by PK (which almost the fastest query your DB can do), you'll only see the network latency.
Bad news is that it will probably get worse if Java and the DB are on separate machines !


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 05, 2006 6:58 am 
Beginner
Beginner

Joined: Sat Jan 01, 2005 12:18 pm
Posts: 23
Actually there is a network latency there but its marginal!

If I connect to the database with a client like psql I have no performance problems like described in the Way 1.

I think I found the problem. I use Springs Hibernate support and used DriverManagerDataSource to connect to the database. DriverManagerDataSource seems to create a new connection on every call and that might create this huge overhead.


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.