A Curious Mind
#tastic

NHibernate Optimizations

Thursday, October 19, 2006 12:31 AM

So today I spent some time optimizing the performance of the site. I have been putting this kind of work on the back burner for quite a while now, while I was trying to get the application up and running. But, oh my geez this is bad. My Sign In to Member Homepage was executing near 300 SQL statements. *blush* Well with a simple change I was able to get it down to about 80 which is still waaaaay to much. Geez, where did I go wrong?

I think I over connected my domain model and now I have to take it apart. Except, how do I do that. It makes sense as it is right now. So I guess I am going to have to remodel some of my entities to make the load not so large. I still think its funny, 300 queries.

So if you have any suggestions I am all ears.


Feedback

# re: NHibernate Optimizations

Are you utilizing lazy loading at your aggregate boundaries or crowded associations? This should cut down on the amount of statements...

A friend of mine once suggested to keep the interconnectedness (word?) to a minimum and instead facilitate the data retrieval through querying.

A different friend suggests creating a tightly interconnected object model and you can do most of your work via object graph traversal.

I fall somewhere in the middle, but I'm always a bit curious as to which is better in terms of performance vs. elegance. 10/19/2006 3:13 AM | Ben Scheirman

# re: NHibernate Optimizations

Lazy Loading is the best way to optimize, both for collections and for the classes themselves.
Here there is a diagram of a small part of my object model:
http://www.ayende.com/Blog/WorkingWithDeepObjectGraphsAndNHibernate.aspx

As you can see, it is highly connected graph, but the connected graph is there for me to work with, not to load data from.

I set everything to lazy, and then I handle the case where I got performance issues by loading the data in advance, so I have the data but I traverse the object graph instead. 10/19/2006 4:44 AM | Ayende Rahien

Post a comment





 

Please add 3 and 1 and type the answer here: