-->
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.  [ 9 posts ] 
Author Message
 Post subject: hibernate.cache.use_query_cache and long running batch
PostPosted: Mon Jul 11, 2005 4:20 pm 
Expert
Expert

Joined: Sat Jan 17, 2004 2:57 pm
Posts: 329
Location: In the basement in my underwear
We've got a rather lengthy batch process that may end up inserting a large amount of data so we've been liberally using flush and clear on the sesssion to keep memory usage down.

However, running through a profiler I noticed that we were still holding references to our inserted, updated objects after being flushed and cleared.

Traced it down to the ActionQueue class:

Code:
public void execute(Executable executable) {
      final boolean lockQueryCache = session.getFactory().getSettings().isQueryCacheEnabled();
      if ( executable.hasAfterTransactionCompletion() || lockQueryCache ) {
         executions.add( executable );
      }
      if (lockQueryCache) {
         session.getFactory()
            .getUpdateTimestampsCache()
            .preinvalidate( executable.getPropertySpaces() );
      }
      executable.execute();
   }


Looks like since we have the query cache enabled for a few select queries that our inserts are getting cached in the executable list so that the afterTransactionCompletion method can use them.

Is there any way to have this behave a bit 'better' for our batch update case w/o having our new objects cached or do we need to make a choice of query cache enabled or disabled and live with the outcome?

We could possibly be dealing with 50, 000 to 60, 000 entities for some of our larger batches and I would prefer not to have them lingering in memory for any longer than they are needed.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 12, 2005 10:29 am 
Expert
Expert

Joined: Sat Jan 17, 2004 2:57 pm
Posts: 329
Location: In the basement in my underwear
Just as an example, on one of our larger runs we ended up with an ActionQueue that grew to 140 megs or so. Not so ideal, with the cache criteria turned off the memory consumption was only about 4 megs.

Apparently turning it off isn't an option for us as our reporting will simply choke.

Do I have any other options?

I'm thinking we can batch up our process a bit better, i.e. we're clearing the session more than we need to which results in bringing in multiple instances of support objects which linger around. This will help reduce the amount of clutter but it's not going to get us anywhere near the 4 megs.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 17, 2005 10:15 am 
Newbie

Joined: Wed Mar 03, 2004 11:22 am
Posts: 12
I am having the same problem. I have a long running batch that runs out of memory due to the executions collection filling up in the action queue. I am calling flush() and clear() on the session after every 20 saves, but clear() does not clear the executions collection. Is this a bug?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 10, 2006 4:36 pm 
Newbie

Joined: Wed Dec 08, 2004 9:13 am
Posts: 6
mentiro wrote:
I am having the same problem. I have a long running batch that runs out of memory due to the executions collection filling up in the action queue. I am calling flush() and clear() on the session after every 20 saves, but clear() does not clear the executions collection. Is this a bug?


Can anyone suggest (configuration setting?) a means to avoid the executions collection from filling during a single transaction in whick many records are inserted?

Jason.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 10, 2006 5:00 pm 
Newbie

Joined: Wed Mar 03, 2004 11:22 am
Posts: 12
You need to disable both hibernate.cache.use_query_cache and hibernate.cache.use_second_level_cache by setting both of them to false. This will prevent executions from being recorded.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 12, 2006 4:50 pm 
Expert
Expert

Joined: Sat Jan 17, 2004 2:57 pm
Posts: 329
Location: In the basement in my underwear
Well, about a year and a half later and I had to dig up this post again. Looks like whatever we were using with a query cache has gone away so I will now be able to finally turn off the query cache.

This will drastically increase our memory consumption on our bigger processes and I've had to fight with a few of them this week so digging up this post was most excellent, lol.


Top
 Profile  
 
 Post subject: A few years later ... :)
PostPosted: Wed Feb 20, 2008 12:21 pm 
Beginner
Beginner

Joined: Tue Jan 04, 2005 5:39 am
Posts: 37
Seems that the problem remains ...

Anyone from Hibernate team, please respond! Is it a bug?

The behaviour could be clearing relevant query cache when clearing Session ...

Thanks!
Michael.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 21, 2008 6:11 am 
Beginner
Beginner

Joined: Tue Jan 04, 2005 5:39 am
Posts: 37
And another issue, it seems that references of CGLIBLazyInitializer survive SessionImpl.clear.

The problem is, that CGLIBLazyInitializer holds a reference to it's target object. So if I'm using lazy many-to-one or one-to-one associations during transaction, those objects won't be cleared during SessionImpl.clear.

Hibernate guys - please reply! It seems that SessionImpl.clear has several issues and is not working so well ... The problem is critical when handling big amounts of data during single DB transaction.

Thanks!
Michael.


Top
 Profile  
 
 Post subject: Reported as bug #HHH-3195
PostPosted: Fri Mar 21, 2008 3:34 pm 
Newbie

Joined: Tue May 24, 2005 8:14 pm
Posts: 3
I entered this issue as bug #HHH-3195:

http://opensource.atlassian.com/project ... e/HHH-3195


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