-->
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: Performance degradation second level cache for large dataset
PostPosted: Tue Jun 06, 2006 12:04 pm 
Newbie

Joined: Tue Jun 06, 2006 11:55 am
Posts: 5
Hibernate version:3.0.5, 3.1.3

Name and version of the database you are using: Oracle 10g

Cache implementation: JBoss Cache, OSCache, EhCache

I have a query that returns 1500 items as a result. I am caching enabled for both the query and the object. The retrieval of this dataset on subsequent request is very slow (200ms - 2s). The situation gets worse in the multithreaded environment. With 50 threads accessing this information simultaneously, the retrieval time starts approaching upto 1minute.

Has anyone encountered this behaviour with second level cache before? I would think that retrieving the data from the cache will be fast. I haven't had this issue with just using the JBoss Cache before. It seems like Hibernate is introducing this delay. Any ideas?

Regards,
Atif Khan


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 06, 2006 5:17 pm 
Senior
Senior

Joined: Tue Mar 09, 2004 2:38 pm
Posts: 141
Location: Lowell, MA USA
Atif,

A couple of questions for you:

1.) what is the query & supporting Java call that loads this data?
2.) Is your cache clustered or does it run in a single instance?
3.) what cache strategy are you using? Read-only, read-write, etc.


Ryan-

_________________
Ryan J. McDonough
http://damnhandy.com

Please remember to rate!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 06, 2006 5:32 pm 
Newbie

Joined: Tue Jun 06, 2006 11:55 am
Posts: 5
Ryan,

Here are the answers:

1). Query:
Code:
from CRONumberDetailsResult as phone_details where phone_details.slotId = :slotId

where CRONumberDetailsResult is a view in Oracle aggregating few tables. There are no joins defined on the mapped Object. It's pretty much a regular Java Bean with 16 attributes.
To get the data I get the named query first and then call list() on it.

2). Cache is not clustered.

3). Cache strategy is set to read-only.

--Atif Khan


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 06, 2006 5:45 pm 
Senior
Senior

Joined: Tue Mar 09, 2004 2:38 pm
Posts: 141
Location: Lowell, MA USA
Since your strategy is read-only, I'll assume that the data is immutable within the application? Some things to look for:

1.) even though you've enabled the query cache, each HQL query must set cachable = true:

Code:
Query query = session.createQuery("from CRONumberDetailsResult as phone_details where phone_details.slotId = :slotId");
query.setCachable(true);


If you don't set cachable = true, you'll always be hitting the database.

2.) There's a difference between query.list() & query.iterate(). Query.list() will get all of the elements in one pass and doen't hot the L2 cache. Query.iterate() will issue a query to load all of the PKs in the result set. As you iterate over the results, it will check the cache for an entry.

One last thing to check: how long does the plain JDBC query take to execute & return the same set of data?

Hope this helps.

Ryan-

_________________
Ryan J. McDonough
http://damnhandy.com

Please remember to rate!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 06, 2006 5:59 pm 
Newbie

Joined: Tue Jun 06, 2006 11:55 am
Posts: 5
1). Query is set as cacheable="true" in the mapping file. After the first request it's pulling the data from the cache.

2). I am not sure what you mean by "hot the cache" here, but I can try the iterate option as well.

3). On an average the direct JDBC takes 55ms.

--Atif Khan


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 06, 2006 9:44 pm 
Senior
Senior

Joined: Tue Mar 09, 2004 2:38 pm
Posts: 141
Location: Lowell, MA USA
Sorry Atif, my fat fingers got in the way. I meant to say "hit the cache."

Ryan-

_________________
Ryan J. McDonough
http://damnhandy.com

Please remember to rate!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 07, 2006 11:29 am 
Newbie

Joined: Tue Jun 06, 2006 11:55 am
Posts: 5
The iterate() didn't solve my problem. In fact it introduced other issues, as the object type returned by the Iterator is not the mapped object type, but it is a CGLIB enhanced class.

Also, the list() method seems to insert/retrieve the query results properly into/from the cache. So, the only difference between the list() and iterate() is that in case of iterate() Hibernate does lazy loading

Thanks
Atif Khan


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 08, 2006 11:47 am 
Beginner
Beginner

Joined: Wed Jun 21, 2006 10:08 am
Posts: 26
Hello,

I don't know if you're still watching this issue, but I am encountering the same performance problem as you.

Did you find any solution?

_________________
- Jonathan


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 08, 2006 1:04 pm 
Newbie

Joined: Tue Jun 06, 2006 11:55 am
Posts: 5
huangjd wrote:
Hello,

I don't know if you're still watching this issue, but I am encountering the same performance problem as you.

Did you find any solution?


We decided to not use the Hibernate second level cache for this particular object. We instead cache it on our own now. Hibernate seems to have issues with a large collection of objects.

--Atif Khan


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.