Question about NH (Hydrate) performance

141 views
Skip to first unread message

Ricardo Pedro

unread,
Sep 2, 2009, 9:17:24 AM9/2/09
to nhusers
Hi to everyone.

I'm an user of NH and I'm using it in lot's of personal and
profissional projects.

This week I found a performance issue on NH that is killing me.

I need to materialize 100.000 objects and NH is taking around 6000 ms
to do that. I think that is too much time and I run the dotTrace
Profiler to sse where is the bottleneck. I found that it is in a
method Hydrate.


I also found a web site http://www.ormbattle.net/ where they compare
several aspectos of NHibernate to Entity Framework.

I found that this aspect of materialize/hydrate objects are a problem
in NH.

What do you think about this. If EF can materialize faster can't NH do
that too ?

Ricardo

Humberto Marchezi

unread,
Sep 3, 2009, 9:08:41 AM9/3/09
to nhu...@googlegroups.com
Hi Ricardo,

Search for stateless session in NHibernate.

Also, read this:
http://ayende.com/Blog/archive/2009/08/15/benchmarks-are-useless-yes-again.aspx

sds
--
Humberto C Marchezi
---------------------------------------------------------
Master in Electrical Engineering - Automation
Software Consultant and Developer
at the Town Hall of Vitória

Fabio Maulo

unread,
Sep 3, 2009, 9:31:40 AM9/3/09
to nhu...@googlegroups.com
Or this

but Humberto... is NH the right tool to upload 100K entities ?



--
Fabio Maulo

Ricardo Pedro

unread,
Sep 3, 2009, 9:37:20 AM9/3/09
to nhusers
Hi Fabio, Thank you very much for your answer.

I can add some more information about this...


The big diference between NH and EF are in the "materialize" or
"hidrate" time!


I don't have the solution for this, but I can add more information to
try solving it...


I run the jetBrains dot Trace, and what I found was the Hidrate
method
to conusme almost all the time. And this is where the transformation
of the SQL result to POCO is made.
This is where the bottleneck is.


I have also tried to use a Stateless Session and the result was even
worse.


I'm getting 60000 rows from the DB and with Session is taking 11000
ms
and with stateless is taking 29000ms





Ricardo


On 3 Set, 14:31, Fabio Maulo <fabioma...@gmail.com> wrote:
> Or thishttp://fabiomaulo.blogspot.com/2009/08/nhibernate-perfomance-analisys...
>
> <http://fabiomaulo.blogspot.com/2009/08/nhibernate-perfomance-analisys...>but
> Humberto... is NH the right tool to upload 100K entities ?http://fabiomaulo.blogspot.com/2009/09/data-mining-in-5-minutes.html
>
> 2009/9/3 Humberto Marchezi <hcmarch...@gmail.com>
>
>
>
>
>
> > Hi Ricardo,
>
> > Search for stateless session in NHibernate.
>
> > Also, read this:
>
> >http://ayende.com/Blog/archive/2009/08/15/benchmarks-are-useless-yes-...
>
> > sds
>
> > On Wed, Sep 2, 2009 at 10:17 AM, Ricardo Pedro <soferrag...@gmail.com>wrote:
>
> >> Hi to everyone.
>
> >> I'm an user of NH and I'm using it in lot's of personal and
> >> profissional projects.
>
> >> This week I found a performance issue on NH that is killing me.
>
> >> I need to materialize 100.000 objects and NH is taking around 6000 ms
> >> to do that. I think that is too much time and I run the dotTrace
> >> Profiler to sse where is the bottleneck. I found that it is in a
> >> method Hydrate.
>
> >> I also found a web sitehttp://www.ormbattle.net/where they compare
> >> several aspectos of NHibernate to Entity Framework.
>
> >> I found that this aspect of materialize/hydrate objects are a problem
> >> in NH.
>
> >> What do you think about this. If EF can materialize faster can't NH do
> >> that too ?
>
> >> Ricardo
>
> > --
> > Humberto C Marchezi
> > ---------------------------------------------------------
> > Master in Electrical Engineering - Automation
> > Software Consultant and Developer
> > at the Town Hall of Vitória
>
> --
> Fabio Maulo- Ocultar texto citado -
>
> - Mostrar texto citado -

Ricardo Pedro

unread,
Sep 3, 2009, 9:47:37 AM9/3/09
to nhusers
I also found that the most time consuming in the stateless session is
creating Proxies when the materializing is done.

I'm using NHibernate 2.0.

The object SessionScope is encapsulating the real Session/
StatelessSession.

This is the TestUnit Code:

[Test]
public void TestStatelessSession()
{
long ts, ts1;
BDManagerBaseClass.GetInstance();
using (SessionScope scope =
BDManagerBaseClass.Instance.NewSessionScope())
{
scope.DisableAutoFlush();
Stopwatch sw = new Stopwatch();
sw.Start();
IList<ConnectionTime> times =
scope.Session.CreateCriteria(typeof
(ConnectionTime)).List<ConnectionTime>();
ts = sw.ElapsedMilliseconds;
}

using (StatelessSessionScope scope =
BDManagerBaseClass.Instance.NewStatelessSessionScope())
{
Stopwatch sw = new Stopwatch();
sw.Start();
IList<ConnectionTime> times =
scope.StatelessSession.CreateCriteria<ConnectionTime>
().List<ConnectionTime>();
ts1 = sw.ElapsedMilliseconds;
}

Console.WriteLine("ts: {0} ms --- ts1: {1} ms", ts, ts1);
}


This is the POCO

[Class(Table = "ConnectionTime", DynamicUpdate=true)]
public class ConnectionTime
{

#region Fields

private BusStop busStop;
private Branch branch;

#endregion


#region Properties

[Id(Column = "ID", Name = "ID", Type = "Int32")]
[Generator(1, Class = "native")]
public virtual int ID { get; set; }


[ManyToOne(Column="EPOCA")]
public virtual Season Season { get; set; }

[ManyToOne(Column="CONNECTION_ID")]
public virtual Connection Connection {get; set;}

[ManyToOne(Column="NR_VARIANTE")]
public virtual TimeVariant TimeVariant { get; set; }

[ManyToOne(Column="DIA_TIPO")]
public virtual Day Day { get; set; }

[Property(Column = "TEMPO_PERCURSO", Type = "Int32")]
public virtual int TravelTime { get; set; }

[Property(Column = "TEMPO_PARADO", Type = "Int32")]
public virtual int StopTime { get; set; }

public virtual int AccumulatedTravelTime { get; set; }

#endregion





}

Fabio Maulo

unread,
Sep 3, 2009, 10:01:08 AM9/3/09
to nhu...@googlegroups.com
I will post about my results using the domain of this test
this time using more than 100K entities.
Btw if you need to load 100K you should use something else, NHibernate is not the tool you are looking for.

2009/9/3 Ricardo Pedro <sofer...@gmail.com>



--
Fabio Maulo

jobsamuel

unread,
Sep 3, 2009, 10:10:44 AM9/3/09
to nhusers
Could the "slowness" in proxy creation be attributed to this "by
design" problem in Castle Dynamic Proxy (basically a limitation in
reflection.emit)
http://support.castleproject.org/projects/DYNPROXY/issues/view/DYNPROXY-ISSUE-98
http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=472622
Would proxy generator help here.

Fabio Maulo

unread,
Sep 3, 2009, 10:16:22 AM9/3/09
to nhu...@googlegroups.com
Ricardo,
Can you explain the real life use-case where you need to upload 100K entities ?
I would add a real life meaning to my post.

2009/9/3 Ricardo Pedro <sofer...@gmail.com>



--
Fabio Maulo

Ricardo Pedro

unread,
Sep 3, 2009, 10:24:10 AM9/3/09
to nhusers
Has I corrected in the next post, I need to retrieve from the DB 60K
entities. And YES this is not too much...

I need to make a TimeEstimator program for a Public Passenger
Transport TimePredicition, and the entitie is the "Connection Times
between 2 BusStop".

Of course I can use a direct SELECT, probably that I will do. No
question on that...

I'm a true believer in NHibernate, so I think that if this is a
bottlneck in NH why don't we look at it... :D

I can help wit more information if needed.

Ricardo

On 3 Set, 15:16, Fabio Maulo <fabioma...@gmail.com> wrote:
> Ricardo,
> Can you explain the real life use-case where you need to upload 100K
> entities ?I would add a real life meaning to my post.
>
> 2009/9/3 Ricardo Pedro <soferrag...@gmail.com>

Ricardo Pedro

unread,
Sep 3, 2009, 10:26:24 AM9/3/09
to nhusers
Good Point But only valid for StatelessSession. In StatefullSession,
the time is consumed in Hydrate.

Will NH 2.1 with other proxy generator help here ????

In fact I'm using CAstle. DynamicProxy!

Sugestions ?

RP



On 3 Set, 15:10, jobsamuel <samu...@gmail.com> wrote:
> Could the "slowness" in proxy creation be attributed to this "by
> design" problem in Castle Dynamic Proxy (basically a limitation in
> reflection.emit)http://support.castleproject.org/projects/DYNPROXY/issues/view/DYNPRO...http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?...

José F. Romaniello

unread,
Sep 3, 2009, 11:12:34 AM9/3/09
to nhu...@googlegroups.com
Would you like to make the same test with linfu and show the results here?

2009/9/3 Ricardo Pedro <sofer...@gmail.com>

Fabio Maulo

unread,
Sep 3, 2009, 11:18:55 AM9/3/09
to nhu...@googlegroups.com
don't waste time... I'm still waiting EF results

2009/9/3 José F. Romaniello <jfroma...@gmail.com>



--
Fabio Maulo

Ricardo Pedro

unread,
Sep 3, 2009, 11:22:38 AM9/3/09
to nhusers
??? Waiting EF results ???

From me ?

I'm trying to change to NH 2.1 so I can see if anything changed.

once again, thank you.

RP

On 3 Set, 16:18, Fabio Maulo <fabioma...@gmail.com> wrote:
> don't waste time... I'm still waiting EF results
>
> 2009/9/3 José F. Romaniello <jfromanie...@gmail.com>
>
>
>
>
>
> > Would you like to make the same test with linfu and show the results here?
> > 2009/9/3 Ricardo Pedro <soferrag...@gmail.com>
>
> >> Good Point But only valid for StatelessSession. In StatefullSession,
> >> the time is consumed in Hydrate.
>
> >> Will NH 2.1 with other proxy generator help here ????
>
> >> In fact I'm using CAstle. DynamicProxy!
>
> >> Sugestions ?
>
> >> RP
>
> >> On 3 Set, 15:10, jobsamuel <samu...@gmail.com> wrote:
> >> > Could the "slowness" in proxy creation be attributed to this "by
> >> > design" problem in Castle Dynamic Proxy (basically a limitation in
> >> > reflection.emit)
> >>http://support.castleproject.org/projects/DYNPROXY/issues/view/DYNPRO....
> >> ..
> >> > Would proxy generator help here.
>
> --

Fabio Maulo

unread,
Sep 3, 2009, 11:30:42 AM9/3/09
to nhu...@googlegroups.com
Not for you but for the community and because what you said.

P.S. At least I must convince myself that is not for you because personal support should have price.

2009/9/3 Ricardo Pedro <sofer...@gmail.com>



--
Fabio Maulo

Cesar Sanz

unread,
Sep 3, 2009, 11:29:35 AM9/3/09
to nhu...@googlegroups.com
It is true that EF materialize POCOs faster than NHibernate?
 
Why?

Fabio Maulo

unread,
Sep 3, 2009, 11:44:37 AM9/3/09
to nhu...@googlegroups.com
waiting....

2009/9/3 Cesar Sanz <the.ema...@gmail.com>



--
Fabio Maulo

Fabio Maulo

unread,
Sep 3, 2009, 11:50:32 AM9/3/09
to nhu...@googlegroups.com
Ok ready to write the post with results...
Guys... I hope this will be the last of this kind of things.

If you need to process 100K entities and NH is too slow for your needs you can use some other tool (including PURE ADO.NET).


2009/9/3 Fabio Maulo <fabio...@gmail.com>



--
Fabio Maulo

John Rayner

unread,
Sep 3, 2009, 12:15:16 PM9/3/09
to nhusers
> I also found that the most time consuming in the stateless session is
> creating Proxies when the materializing is done.

I may not be correct in this, but I think that lazy="false" on the
<class> mapping prevents proxy creation. Have you tried adding this
into all your mappings? (I'm not sure if your application needs lazy-
loading at all).

Cheers,
John

Ricardo Pedro

unread,
Sep 3, 2009, 12:49:33 PM9/3/09
to nhusers
Hi Fabio!

I think that you are over reacting....

My intention is not make a critic to NH!!!

By the contrary, I want to help and say that I like NH too much to
abandon it!!! I think that if EF can (as ORMBattle say, I've not
testet my self yet...) load 100K entities faster than NH, then NH must
do the same...

This is my goal!!! Of course I understand that the architecture is
different, but as a NH user and fan, I think that this can be
possible. And as Obama said: YES WE CAN!

Not put our hands down and say... NO, WE CAN'T !!!!

I'm I wrong ?

RP

Fabio Maulo

unread,
Sep 3, 2009, 1:11:55 PM9/3/09
to nhu...@googlegroups.com
No Ricardo... no... you don't know me and using an e-mail you can't see my face...
Who does not know me call me "BRUTUS"...

btw I'm Italian and you know what this mean... warm-bloody

2009/9/3 Ricardo Pedro <sofer...@gmail.com>



--
Fabio Maulo

Carlos cubas

unread,
Sep 3, 2009, 1:21:25 PM9/3/09
to nhu...@googlegroups.com
Ricardo,

You are missing a little bit of context.  This issue has been beaten to death with a club.
EF is able to achieve such performance because it does not tackle issues that NHibernate has as its primary concerns. (POCO)

Carefully, read Ayende's post along with the comments so you get more context.  Also carefully read ORMBattle.net comments & blog so that you get a sense for how much this issue has been discussed.

-Carlos
 
Practice makes perfect, but if no one is perfect, why practice?




> Date: Thu, 3 Sep 2009 09:49:33 -0700

> Subject: [nhusers] Re: Question about NH (Hydrate) performance

Ricardo Pedro

unread,
Sep 3, 2009, 3:07:24 PM9/3/09
to nhusers
Hi Again...

I read Ayende's blog, but I can't understand from that why EF is does
not tackle all the issues that NHibernat does.
I can understand that nhbernate do more, and better things than EF.

That's why I like NH. Because I trully believe that is better than
EF!!!
But I think that as a user of NH I can ask why can't NH turned the
performance up in some sittuations...

Like the AutoFlush Mode can be tuned and can improve a lot in some
situations, also the loading of entities in a Stateless mode could be
improved.
This is always a 2 side balance. Features vs Performance.


BTW
I've tested with NH2.1 and the performance was improved in the
StatelessSession mode to the same speed as the StatefullSession mode.

I was getting around 15000 ms the 60000 objects in both mode.

Ricardo

PS: I'm portuguese so YES, I do understand what is *warm-bloody*. A
cold beer at a beach can always calm us down :D Come to Lisbon and I
will pay you plenty of them!!!

On 3 Set, 18:21, Carlos cubas <veno...@hotmail.com> wrote:
> Ricardo,
>
> You are missing a little bit of context.  This issue has been beaten to death with a club.
> EF is able to achieve such performance because it does not tackle issues that NHibernate has as its primary concerns. (POCO)
>
> Carefully, read Ayende's post along with the comments so you get more context.  Also carefully read ORMBattle.net comments & blog so that you get a sense for how much this issue has been discussed.
>
> -Carlos
>
> Practice makes perfect, but if no one is perfect, why practice?
>
>
>
> > Date: Thu, 3 Sep 2009 09:49:33 -0700
> > Subject: [nhusers] Re: Question about NH (Hydrate) performance
> > From: soferrag...@gmail.com
> > To: nhu...@googlegroups.com
>
> > Hi Fabio!
>
> > I think that you are over reacting....
>
> > My intention is not make a critic to NH!!!
>
> > By the contrary, I want to help and say that I like NH too much to
> > abandon it!!! I think that if EF can (as ORMBattle say, I've not
> > testet my self yet...) load 100K entities faster than NH, then NH must
> > do the same...
>
> > This is my goal!!! Of course I understand that the architecture is
> > different, but as a NH user and fan, I think that this can be
> > possible. And as Obama said: YES WE CAN!
>
> > Not put our hands down and say... NO, WE CAN'T !!!!
>
> > I'm I wrong ?
>
> > RP
>
> > On 3 Set, 17:15, John Rayner <john.ray...@conchango.com> wrote:
> > > > I also found that the most time consuming in the stateless session is
> > > > creating Proxies when the materializing is done.
>
> > > I may not be correct in this, but I think that lazy="false" on the
> > > <class> mapping prevents proxy creation.  Have you tried adding this
> > > into all your mappings?  (I'm not sure if your application needs lazy-
> > > loading at all).
>
> > > Cheers,
> > > John- Ocultar texto citado -

Fabio Maulo

unread,
Sep 3, 2009, 3:36:39 PM9/3/09
to nhu...@googlegroups.com
My considerations over the matter

P.S. In Lisbon I prefer Oporto or the other wine (I don't remember the name now)... beer in (note the sequence) Ireland, England Czech, German, Belgium 

2009/9/3 Ricardo Pedro <sofer...@gmail.com>



--
Fabio Maulo

Jason Dentler

unread,
Sep 3, 2009, 3:41:06 PM9/3/09
to nhu...@googlegroups.com
Ricardo,

If you can improve the performance of NH without reducing functionality, please submit a patch with the code of your performance enhancements and tests. Until then, have a great day!

Jason
Reply all
Reply to author
Forward
0 new messages