-->
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.  [ 5 posts ] 
Author Message
 Post subject: Bloated Cache
PostPosted: Sun Sep 30, 2007 8:02 am 
Beginner
Beginner

Joined: Mon Jul 30, 2007 4:58 pm
Posts: 21
Hello,

I've encountered a strange problem recently.

Say I have 10000 students in my db. And I load them by

IList<Student> s = studentDao.FindAll();

now that all the students have been loaded within the session.

The problem is after loading such a nubmer any time I make a query like

Student s = studentDao.FindByName("John");

this could take up to 500 ms which is unacceptable.

The only fix I could figure out was clearing the session.

Could anyone tell me if this is a bug ? Why loading many items degrades the performance of my queries ?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 30, 2007 9:49 am 
Regular
Regular

Joined: Wed Oct 25, 2006 10:51 pm
Posts: 71
Hi emperon,

When you load entities into the persistence context, NHibernate keeps information about every single object (for transparent persistence, dirty checking, etc.). When you commit/flush etc, the session uses this information to perform the required operations.

If you have 10,000 entities loaded, this process will be slower than it should be because the session will check all 10,000 entities to find those that must be updated. You should help it avoid this waste by evicting unchanged entities. So that's why clearing the session works for you now. And it's probably what should be done, in your scenario.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 30, 2007 10:04 am 
Beginner
Beginner

Joined: Mon Jul 30, 2007 4:58 pm
Posts: 21
Hi ,

I understand the issue. The thing is flushing and clearing the session in the middle of a transaction just annoys me. May be I should tell nhibernate to retrieve those items read only. Do you know how to do so ?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 30, 2007 10:21 am 
Regular
Regular

Joined: Wed Oct 25, 2006 10:51 pm
Posts: 71
emperon wrote:
May be I should tell nhibernate to retrieve those items read only. Do you know how to do so ?

There is a way to set ReadOnly for just that session... in Hibernate only... it's not implemented in NHibernate. This is how it would look:

session.CreateCriteria(typeof(Foo)).SetReadOnly(true);

In this case, snapshots for dirty checking are disabled in the persistence context.

This was the case for 1.2 anyway, I don't know if anyone is working on this for NHibernate, it's been mentioned in the forum a few times.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 01, 2007 1:57 am 
Regular
Regular

Joined: Wed Oct 25, 2006 10:51 pm
Posts: 71
I just followed this up. Support for ReadOnly is not being looked at by anyone. There is a JIRA issue for it, though.

http://jira.nhibernate.org/browse/NH-908


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