-->
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.  [ 13 posts ] 
Author Message
 Post subject: Performance
PostPosted: Fri Jun 24, 2005 1:20 am 
I have been doing quite a bit of research the last few weeks on NHibernate. We are evaluating different frameworks at my company and NHibernate is one of them.
We currently use a custom framework which is similar to CSLA. I think NHibernate is very interesting and it certainly has a great user base. Unfortunately at this point I think it's power is more geared towards windows apps than web apps. The NHibernate session object can be used in ASP.NET (I wrote my test app using an HttpModule; session-per-request model, which is recommended), although it does not seem to perform as well as I has hoped.
I created a simple CRUD application which displays a grid of records and then allows you to add/delete/update a record. I created one version of this test app using NHibernate and the other using our current BO framework.
Using the exact same environment (my laptop), I load tested it using Application Center Test and am seeing our current framework outperform the NHibernate app by 3-5X. I'm sure this is most likely due to the loading up of the NHibernate Session object for each request.
I would be curious to know if anyone else has any comments on NHibernate performance with ASP.NET. Anyone else done any performance comparison testing?

thanks.


Top
  
 
 Post subject:
PostPosted: Fri Jun 24, 2005 4:53 am 
Senior
Senior

Joined: Sat May 14, 2005 8:40 am
Posts: 130
Creating a session at each request will not harm the performance. I've recently done some load testing and when all data is cached (so no queries take place) a request finishes in 0-15 ms and that is including the creation of the NHibernate Session and attaching the cached objects to the session.

Have you checked the SQL that NHibernate generates? In a default situation without lazy collections and proxies, NHibernate generates lots of queries to make sure that your object graph is completely filled.

A little tweaking with lazy loading or maybe some outer joins can really improve performance.

_________________
Cuyahoga


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 24, 2005 11:04 am 
Newbie

Joined: Mon May 16, 2005 6:48 pm
Posts: 9
When you say "all data is cached", are you referring to cache on the database side?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 24, 2005 12:18 pm 
Senior
Senior

Joined: Sat May 14, 2005 8:40 am
Posts: 130
No, cached in the ASP.NET cache.

I tried to point at the fact that, when there aren't any queries involved, page execution flies even with creation of NHibernate sessions at each request.

_________________
Cuyahoga


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 24, 2005 2:04 pm 
Newbie

Joined: Mon May 16, 2005 6:48 pm
Posts: 9
i'm a little confused.. because I'm not explicitly putting anything in ASP.NET cache. Does NHibernate do something internally w/ ASP.NET cache?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 25, 2005 9:45 am 
Senior
Senior

Joined: Sat May 14, 2005 8:40 am
Posts: 130
No, no the plain NHibernate doesn't do anything with the ASP.NET cache. Perhaps I shouldn't have mentioned it for clarity. I just wanted to make clear that creating a session doesn't cost very much, performance-wise.

_________________
Cuyahoga


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 27, 2005 5:00 pm 
Newbie

Joined: Mon May 16, 2005 6:48 pm
Posts: 9
Ok, well to answer some of your earlier questions.. yes, I am sure that my xml configurations are all fine. I actually took the child/parent nunit test that COMES WITH NHIBERNATE and them moved it over to an asp.net app. So, yes, the relations are fine. I also ran a sql trace while the app was running and the sql looked fine.

I put some timing instrumentation within my code to see how fast the Nhibernate session opens and it is pretty fast. About 20ms. BUT.... run a load test of 200 iterations and that's 4 seconds (20X200). So it does add up when you're talking web applications (session per request).

Still not sure what is causing the rest of the performance lag. For instance, one of my tests using our current framework takes 9 seconds and 25 seconds using Nhibernate. So minus the 4 seconds for the session stuff, I'm still wondering what's causing the other 12 seconds difference. I know NHibernate is doing all kinds of reflection stuff behind the scenes too, so I'm sure that's some of it.

Anyway... I'm sticking with my original statement that NHibernate is more geared (performance wise) for win apps than web apps. I've proven that with an apples-to-apples load test.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 27, 2005 7:29 pm 
Senior
Senior

Joined: Sat May 14, 2005 8:40 am
Posts: 130
You don't accidentally create a new sessionfactory on ever request? This is pretty expensive.

_________________
Cuyahoga


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 28, 2005 12:16 pm 
Newbie

Joined: Mon May 16, 2005 6:48 pm
Posts: 9
I'm using the method described here (http module):
http://blog.benday.com/archive/2005/03/16/198.aspx

And yes, I'm doing session-per-request which means I am opening a new session on each request. And to get the session, I need the SessionFactory.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 28, 2005 2:54 pm 
Beginner
Beginner

Joined: Wed Jun 01, 2005 3:22 pm
Posts: 38
Location: Menlo Park, CA
But the session *factory* should only be created once per application restart.

You can do this by either creating the SessionFactory at Application_Start or by creating it in a static constructor somewhere.

Creating the SessionFactory is incredibly expensive. If you're creating it at every request, your application's performance is going to be terrible.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 28, 2005 3:08 pm 
Senior
Senior

Joined: Sat May 14, 2005 8:40 am
Posts: 130
simon7 wrote:
I'm using the method described here (http module):
http://blog.benday.com/archive/2005/03/16/198.aspx

And yes, I'm doing session-per-request which means I am opening a new session on each request. And to get the session, I need the SessionFactory.


I took a look at the bugtracker sample, and indeed, at every request the sessionfactory is created. This is definately something to avoid. See the above reply for further explanation.

_________________
Cuyahoga


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 30, 2005 11:33 am 
Newbie

Joined: Mon May 16, 2005 6:48 pm
Posts: 9
Okay, I reworked my example to use a static variable for session factory and am only instantiating once. Unfortunately that only took 2 or 3 seconds off of my time. Still 2-3X slower than my other test example.

How is everyone else here dealing with session. As I mentioned (in the example), I am using an IHttpModule, which I think is pretty slick, but maybe that's the problem. Not sure how http modules perform.

thanks for the direction thus far... let me know if you think of anything else...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 05, 2005 11:01 am 
Beginner
Beginner

Joined: Wed Jun 29, 2005 10:40 am
Posts: 30
Location: denver, co
I'm using an HttpModule and get great performance in ASP.NET, and I'm mapping LOTS of classes, in different assemblies, etc. I don't have any idea what could be happening differently, but I'd suggest trying the setup on another computer to see if it's the system or the setup.


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