-->
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.  [ 6 posts ] 
Author Message
 Post subject: Performance of Update versus new insert
PostPosted: Mon Oct 01, 2007 12:37 pm 
Newbie

Joined: Mon Oct 01, 2007 12:29 pm
Posts: 8
I am experiencing a problem trying to update an object that contains a large collection of Doubles:

Code:
@Entity
public class Container {

@CollectionOfElements(fetch = FetchType.LAZY)
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@Cascade(value = CascadeType.EVICT)
private List<Double> elements;

}



When I initially save this object with the elements collection initialized, the save operation takes a short amount of time.

However, if I perform the following steps, the save is very slow:

1. Create a Container object with elements uninitialized and save. (Fast)
2. Load the Container object via the session.load() method.
3. Initialize the elements collection and save the Container object. (Very slow)

I have caching turned on. Also, bulk update is turned on and set to 25, but this is much slower than the first case.

Is there a way to get the performance as in the first case for the second case? Is the update interacting with the cache in a way that is causing this problem?

Thanks,
Anthony


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 01, 2007 6:50 pm 
Regular
Regular

Joined: Sun Sep 30, 2007 7:51 pm
Posts: 93
Just a guess. But after loading the container (step 2), in step 3, if you are creating a new collection, try just to clear existing one, and fill it with objects you want. The loaded collection is probrably different than the one you create with new object (PersistentBag). Hibernate will probably anyway need to create the PersistenBag again, and if the collection is big, it can take a while.

Maybe it helps,
Pavol


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 03, 2007 8:29 am 
Newbie

Joined: Mon Oct 01, 2007 12:29 pm
Posts: 8
I tried your suggestion but it did not fix the problem. Also, I tried debugging the hibernate source code in order to determine where the slow down was occurring. It appears to be doing the same thing in both cases, only the execution of the batch statement in the mysql jdbc code is very slow in the second case versus the first case. Could the problem be in mysql? I am using hibernatetool to generate my database schema. Are there any tricks to enhancing the performance through schema generation?

A little bit more information:

The call to doExecuteBatch in BatchingBatcher is very slow in the second case and very fast in the first case.


Thanks,
Anthony


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 03, 2007 8:35 am 
Regular
Regular

Joined: Sun Sep 30, 2007 7:51 pm
Posts: 93
Hm. If it is mysql, try to find out on mysql server if it suggests some optimization for the tables, etc. Maybe adding indexes or so. I'm sure mysql can do a little in that way, but I can't you tell how.

Also, try to search hibernate docs, wiki etc.. sorry I could not help more.

Regards,
Pavol


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 03, 2007 9:01 am 
Newbie

Joined: Mon Oct 01, 2007 12:29 pm
Posts: 8
I have been looking on the hibernate forums and searching the web. There seems to be very little regarding the performance of batch execution. I am not entirely sure if it is MySQL that is causing the performance problems, though it does seem likely.

I tried removing indexes and foreign key constraints but that did not improve performance.

Anyone have any other ideas?

Thanks,
Anthony


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 05, 2007 7:37 am 
Newbie

Joined: Mon Oct 01, 2007 12:29 pm
Posts: 8
To update those interested in this thread, I have had to go with a non-hibernate solution for this particular save operation. I am using Spring's JdbcTemplate to populate the database table with the updated associated collection. Then, I have to manually invalidate the cached collection and cached entity so that it reflects the database properly. It's an ugly solution, but it works for now. If anyone has any suggestions for sticking with a hibernate only solution, let me know.

Thanks,
Anthony


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