Ayende @ Rahien

Refunds available at head office

NH Prof: NHibernate Profiler vs. Sql Profiler

I recently got a question, asking why someone should pay for NH Prof if SQL profiler is available for (effectively) free?

The answer is actually very easy to answer. I run the following scenario through both NH Prof and SQL Profiler:

using (var s = sf.OpenSession())
using (var tx = s.BeginTransaction())
{
	s.CreateCriteria<User>()
		.Add(Restrictions.NaturalId()
			.Set("Username", "Ayende"))
		.SetCacheable(true)
		.UniqueResult();

	tx.Commit();
}

using (var s = sf.OpenSession())
using (var tx = s.BeginTransaction())
{
	s.CreateCriteria<User>()
		.Add(Restrictions.NaturalId()
			.Set("Username", "Ayende"))
		.SetCacheable(true)
		.UniqueResult();

	tx.Commit();
}

Here is what NH Prof gave me:

image

And here is what I got from SQL Profiler:

image

I think that I have rested my case, pretty conclusively.

Comments

cowgaR
06/23/2009 08:35 AM by
cowgaR

no to mention you need to get SQL Profiler for PostgreSQL (myfav), SQLite, MySQL...etc.

MS SQL Server isn't the only option for few of us, so another nHProfiler (multi-database support) win

Nathan
06/23/2009 10:25 AM by
Nathan

Haven't tried NHProf yet, but MS SQL Profiler is truly an awful piece of software. Its definitely an absolute last resort for me to use it.

Arielr
06/23/2009 10:27 AM by
Arielr

:)

Nice. I don't need persistence in my application, but I'm now starting to wonder if I should YAGNI it anyway. :)

Set
06/23/2009 02:02 PM by
Set

And here is what I got from SQL Profiler:

Come on, you can select the events you need, select the columns you want to see etc.

But then without other kind of logging, I guess there are some informations that might miss.

ChrisB
06/23/2009 02:32 PM by
ChrisB

We have been using NHProf for several weeks now... my statement about the tool would be if you are using NHibernate then NH Prof is a must have tool if you want to be productive. Troubleshooting and performance tuning are much easier.

*We paid beta pricing for our each team member and it has already paid for itself on a single project.

Gareth
06/23/2009 03:29 PM by
Gareth

At first glance I would agree with ChrisB also, but I looked a little closer and realized the difference that wasn't really highlighted in the article. I believe the key point here is that while not only does NH Prof look visually more appealing (which is self apparent), but it can also highlight the caching aspects within NH that the traditional database profiler doesn't see and so cant report! So its not the visual/readability aspect, but it is more of the whole holistic system can be profiled rather than just the raw DB access. Plus as others above have pointed out it is DB agnostic.

Jo&#227;o P. Bragan&#231;a
06/23/2009 04:18 PM by
João P. Bragança

Sql Profiler is completely worthless as a tool especially for non DBAs.

Stephen
06/24/2009 09:13 AM by
Stephen

Uh, I use sql profiler.. it might not be that friendly looking or tell you a huge amount but it can be useful.

tawani
06/24/2009 08:56 PM by
tawani

The point is: the second query is not seen by Sql Profiler.

ChrisB
06/25/2009 02:13 PM by
ChrisB

Both are useful tools, but IMHO this is comaring apples and oranges. For example SQL Profiler can give things like read counts showing where you might investigate adding extra indexes, database issues. NH Prof is about watching the ORM. Checking how sql is constructed via the maps. Number of round trips. One click and you are back to visual studio looking at the calling code.

I must admit I was a little late to NHibernate land, only doing it for about a year, but I am sold. And NH Prof is a great teaching/learning tool for anybody just getting started.

Hudson Akridge
06/25/2009 02:30 PM by
Hudson Akridge

If anyone is seriously questioning NH Profiler vs Sql Profiler, they've only ever used Sql Profiler. I can't imagine anyone who's used both asking that question :)

NH profiler gives you 2nd level cache notifications (very important for performance analysis), and allows you to go all the way up the stack with where certain queries are being executed at (also very important when you get into a command pattern structure). Plus intelligent suggestions to improve performance, along with high level reporting to help you find the pain points rapidly.

And if that wasn't enough, the UI trumps Sql Profiler's hands down. The difference between a good application and a great one is often in the UI design.

Comments have been closed on this topic.