-->
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.  [ 8 posts ] 
Author Message
 Post subject: Extremly bad performance
PostPosted: Sun Dec 27, 2009 5:57 am 
Newbie

Joined: Sun Dec 27, 2009 5:50 am
Posts: 3
When recieving large resultsets using criteria.list() or query.list() Hibernate is really slow. In my case the resultset is about 12 000 rows. The same query takes 120ms to execute directly against the DB but takes >40 sec to excecute through Hibernate. I must do something seriously wrong or is it not possible to recieve large resultsets as list in Hibernate?


Top
 Profile  
 
 Post subject: Re: Extremly bad performance
PostPosted: Mon Dec 28, 2009 3:08 am 
Senior
Senior

Joined: Tue Oct 28, 2008 10:39 am
Posts: 196
What database? Any network between Hibernate and the database? How large are your objects? Do you see GC-calls or heavy CPU-activity during the request? How do you execute the SQL directly? Do you spool the resultset or do you measure just the time of the statement?


Top
 Profile  
 
 Post subject: Re: Extremly bad performance
PostPosted: Mon Dec 28, 2009 5:55 pm 
Newbie

Joined: Sun Dec 27, 2009 5:50 am
Posts: 3
DB: Oracle 11g
Yes the database is on another server. But in our production env the app-server and db-server are on the same gbit LAN and still about the same (about 30sek).
The object mapped by the query has got about 20 properties (String, Integer, Double, Date) and corresponding get/set-methods.Each row in db table is 204bytes.
No GC during execution.
A moderate increase in CPU-activity during processing.
When testing directly I use Oracle SQL Developer, quess it measures the time to execute the statement.


Top
 Profile  
 
 Post subject: Re: Extremly bad performance
PostPosted: Wed Aug 11, 2010 6:54 pm 
Newbie

Joined: Wed Jul 28, 2010 3:31 pm
Posts: 6
Did you find the solution for this problem?
I face the same issue. Any solution is really appreciated.


Top
 Profile  
 
 Post subject: Re: Extremly bad performance
PostPosted: Thu Aug 12, 2010 12:26 am 
Regular
Regular

Joined: Fri Aug 06, 2010 1:49 am
Posts: 102
Location: shynate26@gmail.com
Hi abisheikfoi,

Performance really hits bad when its about thousands of rows. The jinx here is that there is a full row scan on each where condition. Check the query stats and post it here. Try to form the query using index scan. Dont have all the properties included in the mapping document. It would be answerable if you have the query, mapping document & the query stats.

_________________

Cheers!
Shynate
mailto:shynate26@gmail.com
www.CSSCORP.com


Top
 Profile  
 
 Post subject: Re: Extremly bad performance
PostPosted: Thu Aug 12, 2010 2:41 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Quote:
I must do something seriously wrong or is it not possible to recieve large resultsets as list in Hibernate?


It is possible to handle large result sets in Hibernate. I regularly handle queries that return 100000+ entities. Hare are a few things that that you can try/check:

* Use Query.iterate() instead of Query.list(). This keeps the memory usage down if combined with regular calls to Session.clear() or Session.evict().
* Make sure that the JDBC driver knows how to handle large result sets. I use MySQL myself and the default setting in the JDBC driver is to download the entire result set in one go. This uses far too much memory. Don't know anything about Oracle...
* Make sure that you don't have any non-lazy associations or collections. This may result in additional queries for each result in the original result set. If you need to navigate an association later in the code, performance can be increased a lot by including a "fetch join" in the first query.

There are probably other things to do as well, but the three points above have all "bit" me in the past.


Top
 Profile  
 
 Post subject: Re: Extremly bad performance
PostPosted: Thu Aug 12, 2010 5:51 am 
Beginner
Beginner

Joined: Sat Nov 19, 2005 11:54 am
Posts: 22
use the following code for paging
do you need all data in 1 time???
Code:
query.setMaxResults(arg0);
query.setFirstResult(arg0);


Top
 Profile  
 
 Post subject: Re: Extremly bad performance
PostPosted: Thu Aug 12, 2010 7:45 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
chrlon wrote:
When testing directly I use Oracle SQL Developer, quess it measures the time to execute the statement.

Yes but it also does not account for transferring the results across the network to the client and doing things with the result set values. Granted, comparing Hibernate to straight-up JDBC access is like comparing apples and oranges, but here its more like comparing apples to cars.


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