-->
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.  [ 4 posts ] 
Author Message
 Post subject: Bulk Operations + Query Cache leads to High Memory Consumpti
PostPosted: Fri Jul 14, 2006 7:55 pm 
Proxool Developer
Proxool Developer

Joined: Tue Aug 26, 2003 10:42 am
Posts: 373
Location: Belgium
I have to process a large number of entities in a single transaction.
This is a typical batch of operations scenario. Following the recommendations found in the documentation, an abstract alogrithm is as follows:

Code:
for(int i=0; i<100000; i++)
{
    // create and persist a new entity
    Entity e = createEntity(...);
    session.save(e);

    // flush and clear the session periodically to free memory
    if ( (i % 100)==0) {
       session.flush();
       session.clear();
    }
}


This works nicely (and very efficently - thx Hibernate) until the Query Cache is enabled. This seems very suprising at first glance since there is no query involved in the above scenario (the createEntity() method creates a new object from static data).

I ran the test through a memory profiler and discovered that - although the Hibernate session is periodically cleared - it still holds a reference to every operations performed until now (and apparently until the transaction is committed or rolled back) - causing serious memory problems in the above scenario.

For those who know the codebase, these references are kept in the SessionImpl.actionQueue.executions array list.

This behavior is of course causing serious memory problems in the above scenario.

Hence my question:
I'm not questionning this behavior - but would like to find a way to avoid this problem in this particular scenario while still having the query cache enabled for the others.

(forgot to mention this is happening with Hibernate 3.1.2, 3.1.3 & 3.2-cr3 - didn't test the others)


Top
 Profile  
 
 Post subject: Re: Bulk Operations + Query Cache leads to High Memory Consumpti
PostPosted: Wed Oct 30, 2013 2:38 pm 
Newbie

Joined: Mon Mar 27, 2006 2:06 pm
Posts: 5
Ten years later, but I discovered that elements are added to executions list if the queryCache is enabled

For hibernate version lower than 3.5.3

In org.hibernate.engine.ActionQueue
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();
}


and at the Tx end, the transaction tries to be sync to the cache, which is why executions is kept around.
So, I'd recommend to wrap the processor and commit the transaction every X amount of records processed.

Another, very very DIRTY solution is to execute this after your clear(), which
iterates through the executions and syncs them with cache. so this will ONLY work if updated tables != cached tables, and worse, it may break in future hibernate versions. Better to commit periodically instead :)

((SessionImpl) getSession()).getActionQueue().afterTransactionCompletion(true);


...
versiosn higher than 3.5.3 modified the algorithm, so I can't say if it has a bug or not, I'll have to test.


Last edited by dhunter_12 on Thu Nov 21, 2013 8:53 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Bulk Operations + Query Cache leads to High Memory Consumpti
PostPosted: Thu Oct 31, 2013 8:10 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 18, 2012 5:03 am
Posts: 36
Location: Fort Wayne, Indiana, USA
Would you be willing to document this in a new JIRA ticket? If you have something simple we could use to test with, that would be appreciated as well.


Top
 Profile  
 
 Post subject: Re: Bulk Operations + Query Cache leads to High Memory Consumpti
PostPosted: Tue Nov 05, 2013 12:21 pm 
Newbie

Joined: Mon Mar 27, 2006 2:06 pm
Posts: 5
Yes, I have been looking for time to do that. Will update this thread with Jira #


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