-->
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: Perf issue : access to class properties all the time
PostPosted: Tue Nov 06, 2007 8:00 am 
Newbie

Joined: Fri Feb 23, 2007 12:05 pm
Posts: 6
Hello,

I'm working on a big Winform .Net application (framework 2) and I use NHibernate 1.2 (big big thanks to the hibernate team, this product is really fantastic !!!!).

Well, regarding my application, I'm now facing big performance issues and I guess it's because I'm not using NHibernate in the right way :(
I've read the documentation several times, but I suppose there are some key sections that I'm not understanding properly. That's why I'm creating this topic on the forum.

First of all, in my project, I'm using one single Session, created when the user logs in and closed when the application is closed. So this session may be used during several hours. I think I should not do that, but else I've problems to load lazy collections. The session is in "commit" flush mode.

I discovered that when I load multiple objects of persistent type "Class1", and the I try to update 1 single object of persistent type "Class2", Nhibernate reads all (?) the properties of all Class1 objects, even if there are actually no relation between Class1 and Class2.

I suppose it's because my single session checks if any of its objects has been updated ? The problem is that it takes a lot of time to check that.

So, is there a way to "disable" theses checks ? Or should I stop using 1 single session ?

I hope I explained the issue clearly enough :)

Thanks in advance for your support,
Mikvix


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 06, 2007 3:09 pm 
Beginner
Beginner

Joined: Mon Aug 15, 2005 11:38 am
Posts: 28
Hello mikvix,

I do have a couple of questions:

1) What exactly are your performance problems? Is it reading, is it flushing, what are the symptoms?

2) What exactly do you mean with "Nhibernate reads all (?) the properties of all Class1 objects".

All the objects that you ever loaded in your application stay connected to your session, the 1st level cache (unless you evict them). When you do a Flush, NH goes through all the objects connected to the session, checks whether any of the values has changed and commits those changes that it found.

If I interpret your posting correctly, you assume that when you call update on one object, only changes to this object get written to the DB. That's not the case.

Now I'm not sure whether an Update triggers a flush, but as I wrote above, as soon as a flush occurs, NH iterates over all the loaded objects. This allows for making all the changes in memory and committing all changes at once in as few DB roundtrips as possible.

Hope this helps, Christoph


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 06, 2007 3:10 pm 
Beginner
Beginner

Joined: Mon Aug 15, 2005 11:38 am
Posts: 28
Hello mikvix,

I do have a couple of questions:

1) What exactly are your performance problems? Is it reading, is it flushing, what are the symptoms?

2) What exactly do you mean with "Nhibernate reads all (?) the properties of all Class1 objects".

All the objects that you ever loaded in your application stay connected to your session, the 1st level cache (unless you evict them). When you do a Flush, NH goes through all the objects connected to the session, checks whether any of the values has changed and commits those changes that it found.

If I interpret your posting correctly, you assume that when you call update on one object, only changes to this object get written to the DB. That's not the case.

Now I'm not sure whether an Update triggers a flush, but as I wrote above, as soon as a flush occurs, NH iterates over all the loaded objects. This allows for making all the changes in memory and committing all changes at once in as few DB roundtrips as possible.

Hope this helps, Christoph


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 06, 2007 3:12 pm 
Beginner
Beginner

Joined: Mon Aug 15, 2005 11:38 am
Posts: 28
Actually, now that I read your posting again...

If there is truly no connection between Class1 and Class2, and typically you would not need to change objects of Class1 type (e.g. some static data) you could load all required Class1 objects, evict them from the session and then only keep the Class2 objects connected that you're working with.

Regards, Christoph


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 07, 2007 12:10 pm 
Newbie

Joined: Fri Feb 23, 2007 12:05 pm
Posts: 6
Hello Christoph,

Thanks a lot for your help !

It confirms what I understood about NHibernate.

So when I set the Session's FlushMode to "Commit", it will still check if any objects of its 1st level cache has changed ?

Regarding the performance problems : it occurs when I update an object of Class2 and when and only when many Class1 objects had been loaded before.

I will check what happens if I evict the Class1 objects before.

Thanks again,
Mikvix


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.