NHibernate 的事务是否会减慢其他 ADO.NET 连接的速度?
我们正在(缓慢地)将应用程序(使用经典的 ADO.NET DAL)迁移到 NHibernate(遵循“每个请求一个会话模式”和“存储库模式”)。
现在,应用程序处于混合状态(我知道,这很可怕):
一些查询是由一次性 DAO 对象进行的(在其构造函数中打开连接并在其 Dispose() 方法中处理它);< /p>
一些查询是由强类型存储库进行的(其 Get()、Save()、Update() 和 Delete() 方法总是启动一个新事务 - 遵循此建议 http://nhprof.com/Learn/Alerts/DoNotUseImplicitTransactions - 或加入现有事务)。
...并且 DAO 对象进行的查询非常慢(比以前慢两倍)。
我们之前遇到过数据库锁定问题(请参阅NHibernate 的“每个请求一个会话”模式对于长 Web 请求来说不是有点危险吗?),我们解决了它只在需要时打开多个事务,并尽快关闭它们(不仅在当前网络请求的末尾)。因此,现在,我们的 NHIbernate 实现遵循“每个请求一个会话”模式,但具有“每个请求多个事务”。
但速度问题仍然存在。达到与以前相同的速度的唯一方法是完全禁用 NHibernate 事务。
您认为可能是什么原因? NHibernate 事务不与旧的 ADO.NET 连接共享?我们应该做什么?
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 Isn't NHibernate's "one session per request" pattern a bit dangerous for long web requests? ), 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,事务(持续一段时间)可以锁定数据库上的资源。因此会减慢其他操作的速度。
您的交易量应该尽可能小。
如果不可能,请更改隔离模式。 http://en.wikipedia.org/wiki/Isolation_(database_systems)
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)