本文介绍了为什么NHibernate AutoFlush检查如此昂贵?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实际上,我们发现默认的NHibernate(v2.0& 2.1)FlushMode = Auto非常昂贵.查阅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.

在某些生产场景中,其中包含许多项目的更新,多次查询,与FlushMode = Commit相比,使用FlushMode = Auto的过程要长100倍.

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.

在执行涉及多个更新,多个查询等的复杂"会话逻辑时,有关使用FlushMode的任何想法/建议/最佳实践.

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

关于优化nHibernate中的AutoFlush算法的任何想法吗?

Any ideas on optimizing the AutoFlush algorithms in nHibernate?

推荐答案

此缓慢是一个已知问题,在NH中以 NH-1365/GitHib第857期

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

NH中有三种冲洗模式:

There are three flush modes in NH:

  • FlushMode.Auto =需要时刷新(在提交时和查询之前,如果需要).这是默认设置.
  • FlushMode.Commit =仅在提交NH事务时刷新
  • FlushMode.Never =从不刷新(直到调用Flush为止).在插入使用本机(身份)PK生成器的实体时,仍会转到DB . /li>

这篇关于为什么NHibernate AutoFlush检查如此昂贵?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-16 06:41