-->
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: Pre-loading the second level cache. Is it possible?
PostPosted: Thu Feb 28, 2008 1:08 pm 
Newbie

Joined: Thu Feb 28, 2008 11:38 am
Posts: 2
Hi

What is the best way of pre-populating the second level cache? Can this be configured from Hibernate?

Here is an example, let’s say an application has a persistent class called User, and there are 1 million instances in production. As memory is cheap, the server has enough memory to cache all users (e.g. several Gb). Also, start up time is not a problem (within reason).

In a standard cache configuration there will be at least 1 million select statements (e.g. for each user, access a User instance from the code, check in cache + miss, load from database, put instance into cache).

The approach I am thinking is to be able to configure the cache/Hibernate so that it loads all Users with a single “select * from user” statement at start up, and then puts all those users into the cache. This solution will be much faster and generate less network traffic than the 1 million smaller select statements, and this happens at start time rather than normal operation time.

Any ideas? Is this possible?

Many thanks
Eduard


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 28, 2008 1:14 pm 
Senior
Senior

Joined: Fri Jun 01, 2007 12:41 pm
Posts: 121
Second option looks good. But rethink about loading 1 million records from database to hibernate and store them in Second Level Cache. It may increase your start up time.

I prefer first option. Employee record is added to cache when called first time, this may my second level cache (memory) is optimized.

You have covered all the options. You have to choose one. Both are good for me.

I don't think there is no magic in Hibernate to load all these records into cache, except you ask it do it.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 28, 2008 2:11 pm 
Newbie

Joined: Thu Feb 28, 2008 11:38 am
Posts: 2
Thanks sjhyam,

Option 1 and 2 are different approaches to caching. Option 1 is lazy (e.g. “only cache objects if they have been accessed at least once”), while option 2 is more eager (“as I know I will need everything today and I have enough memory, let’s cache everything at start up”).

Sometimes option 1 will be the best one, and others option 2. (I have seen option 2 in several banking back-end applications, although they were using other ORM frameworks to Hibernate).


I however don’t seem to be able to find a way to configure Hibernate, EHCache and/or JBoss TreeCache to support option 2. For the investigation I have done it seems to me Hibernate does not support this. But I might be wrong…


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 28, 2008 2:48 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
I haven't heard of anything like that for HB but I know JBoss cache has something for cache initialization. However, I do recommend you look into some sort of startup hook like a servlet or whatever that was promised to pop out in EJB 3.1 and get a Hibernate session and fire the select statement.


Farzad-


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.