-->
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 problem with session.evict and session.clear
PostPosted: Thu Sep 11, 2008 5:54 pm 
Newbie

Joined: Thu Sep 11, 2008 4:24 pm
Posts: 4
Hibernate version: 3.2.6

I'm using the open session in view pattern with long Conversations, and for my app its often necessary to use session.evict and session.clear to avoid unnecessary memory consumption.

In some cases we deal with persistence of big collections of entities with many relatioships on each entity. Hibernate is doing very well persisting this collections, but when we want to clear the session after a commit, profiling and debugging I see that the session.clear() command takes exponential time to do changes in all proxies on the session. Its the same with the evict() call, for all evict() called for an entity there is an interation on all proxies in the session to find the proxies of this entity.

To give an idea, my entity has 10 proxies. A collection with 30k entities generates 300k proxies in the session. I take less than 1 minute to do what I need and commit everything, but a session.clear() after this takes more than 30 minutes...

I know that is a problem to deal with large collections in session, but we've implemented many features with filters (like auditing, e.g.), that we'll loose doing bulk updates.

Any idea to clear the session in a more efficient way?

A relevant stack of a thread dump:

Code:
4XESTACKTRACE          at java/util/AbstractMap.containsValue(AbstractMap.java:127)
4XESTACKTRACE          at org/hibernate/engine/StatefulPersistenceContext.containsProxy(StatefulPersistenceContext.java:467)
4XESTACKTRACE          at org/hibernate/proxy/AbstractLazyInitializer.isConnectedToSession(AbstractLazyInitializer.java:97(Compiled Code))
4XESTACKTRACE          at org/hibernate/proxy/AbstractLazyInitializer.setSession(AbstractLazyInitializer.java:86(Compiled Code))
4XESTACKTRACE          at org/hibernate/engine/StatefulPersistenceContext.clear(StatefulPersistenceContext.java:184(Compiled Code))
4XESTACKTRACE          at org/hibernate/impl/SessionImpl.clear(SessionImpl.java:255)



The pice of code that does this linear search, in StatefulPersistenceContext is:

Code:
   public boolean containsProxy(Object entity) {
      return proxiesByKey.containsValue( entity );
   }


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 16, 2008 11:32 am 
Newbie

Joined: Wed Aug 31, 2005 2:29 am
Posts: 8
I do have the same problem with my application. Flush performance is poor if too many entities are loaded / modified within one session. So i regularly try to call clear(). But with 3.2.6 the performance for clear() is bad too. When going back to hibernate 3.2.3.ga the performance for clear() is okay.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 10, 2008 9:16 am 
Newbie

Joined: Thu Sep 11, 2008 4:24 pm
Posts: 4
Thanks a lot, looking the source, this is a side-efect of another bug fix.

http://opensource.atlassian.com/project ... se/HHH-511


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.