-->
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.  [ 20 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: How fast is NHibernate
PostPosted: Mon Jan 21, 2008 9:28 am 
Beginner
Beginner

Joined: Mon Jan 21, 2008 8:57 am
Posts: 20
Hi,
I have been looking abit into NHibernate, but would like to know, if there is any resources where they have tested the speed of the NHibernate queries on MSSQL?
I would like to know how big the delay you get when executing the queries in NHibernate compared to doing the queries themselves.
I hope this haven't been answered before, and it is the proper place I ask :)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 21, 2008 10:48 am 
Regular
Regular

Joined: Tue Dec 25, 2007 3:41 pm
Posts: 57
Location: Argentina
Hi,

NHibernate is a great framework, but have a bit of overload on queries, because it do many things, not only execute queries to db.

You can make test by yourself and later tell us the results, could be a nice work.

By the way, if you need bulk operations, you could try with IStatelessSession at trunk. It works without 1st level cache.
https://nhibernate.svn.sourceforge.net/svnroot/nhibernate/trunk/nhibernate/src/NHibernate/IStatelessSession.cs

Best regards.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 21, 2008 10:56 am 
Newbie

Joined: Tue Jan 09, 2007 5:24 am
Posts: 15
Hi Philz - I have asked the same question.

On SQL Server, NHibernate is using sp_executesql to deliver SQL to the server. This SQL is then pre-compiled and reused making it just as fast as an ordinary stored procedure.

See: http://forum.hibernate.org/viewtopic.php?t=982822

Most of the the speed of NHibernate will depend on how exotic your mapping files are. If you only have one table pr class with no object mappings, I would assume NHibernate to be just as fast as any handwritten query.

If you have a lot relations in your NH mapping file, you should consider making your relations lazy, in order to avoid loading a lot of related data.

Also remember that NHibernate is an ORM tool, thus it will probably not be suitable for hard-core database crunching where you need to run through millions of rows very fast.

Cheers,
Thomas


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 21, 2008 11:08 am 
Regular
Regular

Joined: Tue Dec 25, 2007 3:41 pm
Posts: 57
Location: Argentina
Hi,

There is not more overload by mapping complexity, NHibernate read the mappings at the begin and later translate it to a object structure. By the way, there is not a hard work by a complex type mapped. I don't think this could influence.

NHibernate may be suitable for run run through millions of rows very fast, if you use the new feature (for now available at trunk): IStatelessSession.
http://darioquintana.com.ar/blogging/?p=4


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 21, 2008 4:14 pm 
Regular
Regular

Joined: Mon Jul 18, 2005 4:10 am
Posts: 92
Location: Poland
IMHO if we are talkin about "how fast it is" , the most important thing is how you write your applications, not the "core" performance. If you forgot that under those NH "wonders" there are real SQL queries (that's easy!), you can fall into "n+1 selects" problem very fast and it woulld kill every application.

_________________
michal


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 28, 2008 2:40 am 
Beginner
Beginner

Joined: Mon Jan 21, 2008 8:57 am
Posts: 20
Thank you for all your answers. I will look a bit more into NHibernate and then I will post again.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 28, 2008 3:18 am 
Regular
Regular

Joined: Wed Jun 21, 2006 3:13 pm
Posts: 110
For my projects (1 man dev team), I've found that, compared to my old method of writing stored procedures:

- Development time is roughly 30% faster during initial development...
- New features are completed about 10% faster
- Initial application startup (web app) for first request is noticably slower. This goes away for all subsequent requests.
- Reads are not slower. In fact, reads for cacheable data is faster and non-cached items are still very responsive. All data is sent to sp_executesql as parameters. sql server will cache the execution plan and parameters so, while it's not quite as fast as a stored proc, you'll be hard-pressed to find a significant difference in many instances.

nhibernate is not good for bulk operations.

I've found the best way to ease into things is to start with using nhibernate as the connection manager to the database. then, move some of your simpler objects to nhibernate... I did that first for all of my lookup objects (frequent read - infrequent write). It let me get my toes wet and alos see how nhibernate would perform (very nicely).


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 28, 2008 6:03 am 
Beginner
Beginner

Joined: Mon Jan 21, 2008 8:57 am
Posts: 20
benhyrman wrote:
For my projects (1 man dev team), I've found that, compared to my old method of writing stored procedures:

- Development time is roughly 30% faster during initial development...
- New features are completed about 10% faster
- Initial application startup (web app) for first request is noticably slower. This goes away for all subsequent requests.
- Reads are not slower. In fact, reads for cacheable data is faster and non-cached items are still very responsive. All data is sent to sp_executesql as parameters. sql server will cache the execution plan and parameters so, while it's not quite as fast as a stored proc, you'll be hard-pressed to find a significant difference in many instances.

nhibernate is not good for bulk operations.

I've found the best way to ease into things is to start with using nhibernate as the connection manager to the database. then, move some of your simpler objects to nhibernate... I did that first for all of my lookup objects (frequent read - infrequent write). It let me get my toes wet and alos see how nhibernate would perform (very nicely).


This is ment for a Windows Application, but how does NHibernate work out if you have a lot of users? Lets say 100+ ? Also is there any problems (speed, programming etc.) with Binaery fields?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 28, 2008 9:28 am 
Regular
Regular

Joined: Tue Dec 25, 2007 3:41 pm
Posts: 57
Location: Argentina
@benhyrman: did you use IStatelessSession for Bulk operations? That is serves to Bulk Operations.
http://www.hibernate.org/hib_docs/v3/api/org/hibernate/StatelessSession.html

_________________
Dario Quintana


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 28, 2008 12:34 pm 
Regular
Regular

Joined: Wed Jun 21, 2006 3:13 pm
Posts: 110
darioquintana wrote:
@benhyrman: did you use IStatelessSession for Bulk operations? That is serves to Bulk Operations.
http://www.hibernate.org/hib_docs/v3/api/org/hibernate/StatelessSession.html


Dario, I'm having trouble finding a reference to stateless session in either the 1.2 docs or 1.2 source code. I wasn't aware the feature had been ported from Hibernate. Is it in the code repository?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 28, 2008 12:54 pm 
Regular
Regular

Joined: Wed Jun 21, 2006 3:13 pm
Posts: 110
Philz wrote:
This is ment for a Windows Application, but how does NHibernate work out if you have a lot of users? Lets say 100+ ? Also is there any problems (speed, programming etc.) with Binaery fields?


Philz. A better way to think about it is this:

NHibernate is a wonderful abstraction layer for handling database connections, data retreival, and persistance. NHibernate is not a magic bullet. A poorly architected system will not be saved by NHibernate. At the same time, a well-done system will benefit greatly, in my opinion, from NHibernate.

If I were in your shoes, I would implement a test client around the critical pieces of your system and then simulate load up to your expected peak user limit. That will answer your question for you better than anything on if it'll impact or help your app.

To be honest, I haven't done much with binary fields in nhibernate but, again, a quick test will answer your question for you.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 28, 2008 12:57 pm 
Newbie

Joined: Tue Oct 11, 2005 12:20 pm
Posts: 4
In my first post of this thread there is a link with an example.

For use IStatelessSession you need use NHibernate from the trunk, yet there isn't a release, but soon:
https://nhibernate.svn.sourceforge.net/ ... ate/trunk/


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 28, 2008 1:02 pm 
Regular
Regular

Joined: Tue Dec 25, 2007 3:41 pm
Posts: 57
Location: Argentina
[Sorry the double post, wrong account]
In my first post of this thread there is a link with an example.

For use IStatelessSession you need use NHibernate from the trunk, yet there isn't a release, but soon:
https://nhibernate.svn.sourceforge.net/ ... ate/trunk/

_________________
Dario Quintana


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 28, 2008 2:47 pm 
Regular
Regular

Joined: Wed Jun 21, 2006 3:13 pm
Posts: 110
darioquintana wrote:
[Sorry the double post, wrong account]
In my first post of this thread there is a link with an example.

For use IStatelessSession you need use NHibernate from the trunk, yet there isn't a release, but soon:
https://nhibernate.svn.sourceforge.net/ ... ate/trunk/


I'm sorry Dario, I completely missed that in your post. I'm going to check that out for sure.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 31, 2008 5:38 am 
Beginner
Beginner

Joined: Mon Jan 21, 2008 8:57 am
Posts: 20
I was a little worried if NHibernate would be too slow, so I did a few tests to see fast it was compared to writing the sql myself.
I was trying to insert a binary field, author and programID. When I did the sql manual it took 261ms to insert one row. When I inserted the row 10 times it took 344ms, and it took 526ms to insert the fields 100 times, When I did it with NHibernate I got the following times:
1 insert – 501ms
10 inserts – 873ms
100 inserts – 984ms

These times would vary quite a bit, but I think these is the apprx values.

The code to generate the NHIbernate looked like this:

Code:
        public void PopulateData(int runs)
        {
            Configuration cfg = new Configuration();
            cfg.AddAssembly("HibernateTest");
            for (int i = 0; i < runs; i++)
            {

                ISessionFactory factory = cfg.BuildSessionFactory();
                ISession session = factory.OpenSession();
                ITransaction transaction = session.BeginTransaction();

                FileStream fs = new FileStream(@"C:\maintest2.doc", FileMode.Open);
                byte[] dataArray = new byte[fs.Length];
                ReadData(fs, dataArray);
               
                TestSpec testSpec = new TestSpec();
                testSpec.CreationDate = DateTime.Now;
                testSpec.Author = "Philip "+i;
                testSpec.Description = dataArray;
               


                fs.Close();
                session.Save(testSpec);

                // commit all of the changes to the DB and close the ISession
                transaction.Commit();
                session.Close();
            }
        }


I just thought you guys might be interested in the results. So it looks like NHibernate is quite a bit slower, when you work with binary fields, than by doing it yourself.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 20 posts ]  Go to page 1, 2  Next

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.