NHibernate 慢速映射

发布于 2024-08-16 21:08:07 字数 577 浏览 5 评论 0原文

我的问题是我可以做什么来确定缓慢的原因,或者在不知道确切原因的情况下我可以做什么来加快速度。

我正在运行一个简单的查询,看来映射回实体需要很长时间。结果集是350,在我看来这并不是多少数据。

IRepository repo = ObjectFactory.GetInstance<IRepository>();
var q =  repo.Query<Order>(item => item.Ordereddate > DateTime.Now.AddDays(-40));

foreach (var order in q)
{
    Console.WriteLine(order.TransactionNumber);
}

探查器告诉我它正在执行查询 7ms / 35257ms,我假设前者是来自数据库的实际响应,后者是 NH 完成它的魔力所需的时间。

35秒太长了。这是一个简单的映射,一张表,嵌套组件,使用流畅的接口来做映射。我只是启动一个简单的控制台应用程序并运行一个查询,在 SessionFactory 初始化后测量速度,应该只有一个会话,并且我没有使用事务。

谢谢

My question is what can I do to determine the cause of the slowness, or what can I do to speed it up without knowing the exact cause.

I am running a simple query and it appears that the mapping back to the entities is taking taking forever. The result set is 350, which is not much data in my opinion.

IRepository repo = ObjectFactory.GetInstance<IRepository>();
var q =  repo.Query<Order>(item => item.Ordereddate > DateTime.Now.AddDays(-40));

foreach (var order in q)
{
    Console.WriteLine(order.TransactionNumber);
}

The profiler is telling me it is executing the query 7ms / 35257ms, I am assuming that the former is the actual response from the db and the latter is the time it takes NH to do it's magic.

35 seconds is too long. This is a simple mapping, one table, nested components, using fluent interface to do mappings. I just start up a simple console app and run the one query, the slowness is measured after the SessionFactory is initialized, there should only be one session, and I am not using a transaction.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

清眉祭 2024-08-23 21:08:07

如果您的数据库查询返回得很快,那么问题就出在代码本身的某个地方。它不太可能出现在 NHibernate 中。您的评论暗示您正在使用自定义用户类型,并且很可能其中存在特别低效的东西。我猜你正在使用 NProf 作为你的分析器?也许您应该使用直接的 .NET 分析器并查看代码本身的性能,包括这些自定义类型?类似 Ants、dotTrace 或 AQTime。

If your database query is returning quickly, then the problem is somewhere in the code itself. It's unlikely to be in NHibernate. Your comments imply that you are using custom user types, and it may very well be that there's something particularly inefficient in there. I am guessing you are using NHProf as your profiler? Perhaps you should use a straight .NET profiler and look at the performance of the code itself, including these custom types? Something like Ants, dotTrace or AQTime.

女中豪杰 2024-08-23 21:08:07

您可能正在用户类型中执行一些需要花费大量时间的操作

It is likely that you are doing something in your user types that takes a lot of time

孤独难免 2024-08-23 21:08:07

尝试禁用 log4net。如果它可以加快速度并且您仍想将其用于其他目的,请仅禁用 nhibernate。

Try disabling log4net. If it speeds things up and you still want to use it for other purposes, disable only nhibernate.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文