NHibernate begin transaction and commit with no statements takes more then 4 seconds

457 views Asked by At

I run Nh-Prof on our production and found that the time to open NHibernate session, begin transaction and commit sometimes takes more than 4 seconds even there are no state/queries to database.

** I know that open transaction and commit it with no reason (no statements) is a bug.

This is what I see in Nh-Prof:

begin transaction with isolation level: Unspecified
commit transaction

Any suggestions?

1

There are 1 answers

0
Firo On

Most probable reason:

the session used is "full" of objects and on Commit it checks each object if it has changed to generate an update statement. Even if nothing changed the check is costly.

You can check session.GetSessionImplementation().PersistenceContext.EntitiesByKey.Count to see how many objects are there.

What you can do about it:

  • don't use this session to load readonly data (e.g. fillling a readonly grid)
  • use session.Evict along the way on objects you don't need anymore for the transaction and haven't changed