-->
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.  [ 10 posts ] 
Author Message
 Post subject: Performance issues
PostPosted: Wed Mar 12, 2008 10:13 am 
Newbie

Joined: Fri Mar 07, 2008 2:24 am
Posts: 6
Hi,
I am facing major issues related to hibernate performance. So while trying to optimize my application i came across following queries and doubts. Can anybody plz help:

(a) While reading whole graph of objects from database, i thought using setReadOnly on 'Session' object or 'StatlessSession' should benefit but it seems they work only on single object and not on graphs. Because i started getting TransientObject like exceptions.

But i was just wondering if the object graph i am populating is to be used only for READONLY purpose then , is not there any provision available in Hibernate to speed up things, maybe by disabling some interceptors etc ?

(b) I am using Hibernate with PostgreSQL database. And the Id generator type being used is 'native'. But what i observed is that Hibernate not only fires one query extra for fetching the sequence (nextVal()) before inserting every object but also brings that value to client side from DBMS Server. So, is it necessary for Hibernate to do so ?

(c) I tried to save parrallelly using multiple sessions and threading (separate session per thread) but did not find even a 'second' of improvement. Is it something to do with Hibernate 'save' method ?

Thanks in advance !


Top
 Profile  
 
 Post subject: Re: Performance issues
PostPosted: Wed Mar 12, 2008 2:19 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
a - Hmmm, I think these kind of settings are minor performance improvement. For extreme performance improvement when reading data you need to look into L2 cache.


b - Yes it does. It needs to set the foreign keys and ....


c - why do you think that should improve performance?




Farzad-


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 13, 2008 1:25 am 
Newbie

Joined: Fri Mar 07, 2008 2:24 am
Posts: 6
Hi,
thanks for quick help !
Actually i have to save around 20000 objects at the same time. I can categorize them on some basis (say into 10 lots). So, I thought to save them parallelly to improve performance.

Also, can u please tell me if i have set jdbc batch size to 20-40 but i flush the session after saving 1000 objects then will that improve the performance.

My problem is the data i m saving has tree like structure. Table and column names are not known to me in my aplication, as the application is so generic :(.

So, i have to save from the root level of the tree and hence i cannot even say clear session in-between. I was wondering whether Hibernate itself can detect the relationships and can clear the session on setting some property xyz..

thanks !


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 13, 2008 11:03 am 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
Quote:
Actually i have to save around 20000 objects at the same time. I can categorize them on some basis (say into 10 lots). So, I thought to save them parallelly to improve performance.


That's a very tricky question and it really depends what database you are talking about. I suggest that you seek advice from a DBA. If you ask me I would drop all indexes if nobody else is looking at the database. From the Java side make sure you have the maximum bandwidth between your computer and the db machine (sometimes you can tweak packet size and so) and tweaking batch size is also good. I don't suggest you call the flush itself but seriously I might not be the right person to comment on this since I never did bulk loading and stuff. Hmm, one another thing I remember is reducing locking during updates. In some dbs like SQL Server you can tweak this to a great deal (a row lock per update in preferable).

Quote:
So, i have to save from the root level of the tree and hence i cannot even say clear session in-between. I was wondering whether Hibernate itself can detect the relationships and can clear the session on setting some property xyz..


You lost me here. Say again.


Farzad-


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 14, 2008 1:17 am 
Newbie

Joined: Fri Mar 07, 2008 2:24 am
Posts: 6
Thanks Farzad.

By
So, i have to save from the root level of the tree and hence i cannot even say clear session in-between. I was wondering whether Hibernate itself can detect the relationships and can clear the session on setting some property xyz..

I meant i am also worried about saving so many objects at the same time as Hibernate will tru to cache them all. So , i was wondering whether Hibernate can automatically clear session after it caches some number of objects.

Is it possbile that Hibernate is taking time to genearte so many SQLs as the number of objects being saved is too high.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 14, 2008 9:43 am 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
Quote:
I meant i am also worried about saving so many objects at the same time as Hibernate will tru to cache them all. So , i was wondering whether Hibernate can automatically clear session after it caches some number of objects.


The trick is too do a count yourself, lets say every 1000 objects, and flush the session and call clear after flush. This frees session's memory.

Quote:
Is it possbile that Hibernate is taking time to genearte so many SQLs as the number of objects being saved is too high.


Then you should see a high cpu usage on your machine which I really doubt you do.



Farzad-


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 14, 2008 10:46 am 
Newbie

Joined: Fri Mar 07, 2008 2:24 am
Posts: 6
Actually in my application i have to save an object graph having tree like structure. Also, this graph contains dissimilar objects. I get this graph directly from JAXB (later modified by HyperJAXB). Hence, i have little control over it.

Today when i analyzed the queries generated by Hibernate, i had following obervations:
(1) For inserting 4 records, hibernate fires 4 inserts, 5 updates and 4 select statements for getting next sequence for primary key.
It is really huge overhead. Can i somehow reduce or eliminate the
'update' queries ?

(2) I am using PostgreSQL 8.1 , JDBC driver type 4. I set jdbc.batch_size property but hardly found any difference :(. Here, note that i do not flush after (rather i cannot) saving the number of objects = batch size.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 14, 2008 10:52 am 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
What are the updates for?



Farzad-


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 17, 2008 12:45 am 
Newbie

Joined: Fri Mar 07, 2008 2:24 am
Posts: 6
Updates are for updating foreign keys as hibernate fires one extra update query for every foreign key relationship.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 17, 2008 10:27 am 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
onkar wrote:
Updates are for updating foreign keys as hibernate fires one extra update query for every foreign key relationship.


Umm, it depends how you have done the relationship. The key here is that hibernate will put foreign keys in insert if it is able to save a parent record before saving a child record. however, sometimes hibernate can not do this and therefore it updates foreign keys after inserting children. Show me the mapping between the parent class and all of it's children and also say which one of the children is the one in question here.



Farzad-


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 10 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.