views:

55

answers:

1

We're (slowly) moving an application (with a classic ADO.NET DAL) to NHibernate (following both "one-session-per-request pattern" and "repository pattern").

The application, right now, is in a hybrid state (I know, it's horrorful):

  • some query are made by disposable DAO objects (that open a connection in their constructors and dispose it in their Dispose() method);

  • some query are made by the strongly typed repositories (whose Get(), Save(), Update() and Delete() methods always start a new transaction - following this suggestion http://nhprof.com/Learn/Alerts/DoNotUseImplicitTransactions - or join an existing transaction).

... and queries made by DAO objects are very slow (two times slower than before).

We previously had a problem with database lockings (see http://stackoverflow.com/questions/3621271/isnt-nhibernates-one-session-per-request-pattern-a-bit-dangerous-for-long-web ), and we solved it opening multiple transactions only when needed, and closing them as soon as possible (not only at the end of the current web request). So, right now, our NHIbernate implementation follows the "one-session-per-request" pattern, but with "multiple-transactions-per-request".

But the speed problem remains. The only way to achieve the same speed as before is to disable NHibernate transactions completely.

What do you think could be the cause? The NHibernate transaction not shared with old ADO.NET connections? What should we do?

+1  A: 

Yes transactions (that last for some time) can lock resources on the database. And therefore slow down other operations.

Your transactions should be the smallest possible.

If not possible, change your isolation mode. http://en.wikipedia.org/wiki/Isolation_(database_systems)

Pierre 303
Do yoy think that attaching the transaction opened by NHibernate to the DAO's connection could solve the problem? Or queries inside the same transaction are slowed, too?
Notoriousxl
No a transaction should take care of a particular suite of operations and maintain consistancy. Try to split your large transaction in smaller batches if this doesn't introduce consistancy problems.
Pierre 303
As far as I've seen from the profilers (I didn't write the application, nor I partecipated in the "NHibernate switch"), transactions are yet very small, and only used inside Repositories' methods, which are very minimal... so the bug is very difficult to find :( (I'm using NHProf and SQL server profiler - I am a "DB-noob" - ... maybe I'm using the wrong debugging tools to check for unclosed transactions)
Notoriousxl
You are right, I know nothing to your application, I can only answer yes to your question. I suggest you to ask a database specialist on serverfault.com
Pierre 303
@Pierre: don't worry... also because you were right :) Today we've found that the database were slow only because there were an older version of the "buggy" web app running on the web server; updating and restarting it solved everything, so the problem was effectively the "long transaction"
Notoriousxl