Batching support in NHibernate

As of about 90 minutes ago, NHibernate has batching support. :-D

All the tests are green, but there may be things that broke in exciting ways, so I encourage you to try it out and see if you can break it. This functionality exists only for SQL Server, and only on .Net 2.0 (for complaints, go directly to the ADO.Net team).

You can enable this functionality by adding this to your hibernate configuration.

<

add key="hibernate.batch_size" value="10" />

Setting this size to very large number and treating NHibernate as an OO tool for bulk inserts is still not recommended.

My previous tests showed about 50% performance benefits over normal calls, I decided to try to take the new code for a speed using NHibernate's perf tests. They are fairly simple, but they are at least an indication of what is going on. The tests I run were all run against a local instance of SQL Server, with log level set to WARN. The test just compare similar operations using NHibernate and direct ADO.Net for some operations, usually inserts / deletes in increasing amounts. (For reference, I'm running the Simultanous() test from PerformanceTest fixture).

I should also mention that these are by no mean real benchmarks, it is more in the way of an indication.

With no batching:

(Image from clipboard).png

As you can see, there isn't much of a performance difference between the two, NHibernate has about 15% overhead, mostly it can be seen as a background noise, especially on the lower ranges.

Let us try with a batching of 25, shall we?

(Image from clipboard).png

Now the roles are reversed, and it is NHibernate that is faster. In fact, in this benchmark, it was on average faster by 25% - 30% than the direct ADO.Net code (without batching). Just for kicks, I run the benchmark with batch size of 256, and got about 30% - 45% improvements.

(Image from clipboard).png

All in all, I think that I like this :-D

As a side note, most of the performance in an ORM is not in the INSERT / UPDATE / DELETE side of things, but rather in how smart the engine in SELECTing the data. Issuing a thousands unnececary SELECTs is going to be a performance hog no matter what you do.

Print | posted on Saturday, September 16, 2006 2:29 AM

Feedback


Gravatar

#  9/18/2006 10:22 AM Alessandro Cavalieri

How can I use the latest build of NHibernate with ActiveRecord? Just copy the NHibernate Assembly in my lib directory with the latest AcriveRecord assemblies and reference them togheter?

Thanks,
Alessandro


Gravatar

#  9/18/2006 10:35 AM Ayende Rahien

This is more or less all you need to do.
Make sure that you build AR, and not just copy the DLLs.


Gravatar

#  10/26/2006 11:57 PM Steve Guidi

Ayende -- this is really neat!

I haven't looked at the source code yet, but do you recall if the configuration is supported through the session factory configuration file (e.g. &lt;property name=&quot;hibernate.batch_size&quot;&gt;10&lt;/property&gt;)?

Also, if the session is explicitly flushed before the batch size threshold is reached, then I presume that the full effects of the batch operation are lost. The worst case being flushing after each ISession.Save() operation, effectively eliminating the batch feature.


Gravatar

#  10/27/2006 12:20 AM Ayende Rahien

@Steve,
Exactly right on all counts


Gravatar

# More On Binsor: Natrual Component References 2/3/2007 7:47 AM www.ayende.com


Gravatar

# NHibernate e le prestazioni... 2/3/2007 7:47 AM blogs.ugidotnet.org

Comments have been closed on this topic.