Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is NHibernate AutoFlush check so expensive?

Tags:

nhibernate

In practice we are finding the default NHibernate (v2.0 & 2.1) FlushMode=Auto to be extremely expensive. Reviewing the NHibernate source suggests that the algorithms for determining what needs to be flushed rely on brute-force of looping through all entities in session, and this occurs for every query run in a transaction.

In some production scenario with updates on many items, with multiple queries we have seen the process 100 times longer with FlushMode=Auto compared to FlushMode=Commit.

Any thoughts/advice/best practices for usage of FlushMode when performing 'complex' session logic involving multiple updates, multiple queries etc.

Any ideas on optimizing the AutoFlush algorithms in nHibernate?

like image 329
Pawel Avatar asked Nov 13 '09 01:11

Pawel


1 Answers

This slowness is a known issue and is tracked in NH as NH-1365/GitHib Issue 857

There are three flush modes in NH:

  • FlushMode.Auto = Flush when needed (on commit and before queries, if needed). This is the default.
  • FlushMode.Commit = flush on commit of NH transaction only
  • FlushMode.Never = never flush (until Flush is called). This will still go to DB on insert of entities that use native (identity) PK generator.
like image 103
Stop Putin Stop War Avatar answered Oct 01 '22 05:10

Stop Putin Stop War