NHibernate Profiler - 数据库持续时间和总持续时间之间存在巨大差异?

发布于 2024-10-10 13:16:46 字数 263 浏览 2 评论 0原文

我有一个广泛使用 NHibernate 的应用程序。我开始使用 NHibernate Profiler 来识别可能的性能问题。我的问题与查询持续时间统计相关。

该统计数据分为数据库持续时间和总持续时间。从我读到的来看,数字应该非常接近。然而,我看到了相对较大的差异,我正在试图找出这些差异的根源。这是一些数据

alt text

知道我可以从哪里开始解决这些问题吗?

I have an application that makes extensive use of NHibernate. I've started using the NHibernate Profiler to identify possible performance issues. My question is related to the Query Durations statistic.

The stat is broken down in Database Duration and Total Duration. From what I've read, the numbers should be very close. However, I'm seeing relatively large disparities and I'm trying to figure out the source of these. Here's some data

alt text

Any idea on where I can start to fix these issues?

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

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

发布评论

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

评论(4

池予 2024-10-17 13:16:46

您的应用程序使用 log4net 吗?如果是这样,您应该检查 log4net 配置并减少从 NHibernate 记录的数据量。

我现在正在处理的一个项目的示例:对于返回 60 行/对象的查询,将 DEBUG 级别的所有 NHibernate 日志消息记录到文件中会将 NProf 报告的总持续时间从 8 毫秒增加到大约 8000 毫秒!

限制 NHibernate 输出的示例配置:

<root>
    <level value="ALL" />
    <appender-ref ref="console" />
    <appender-ref ref="trace" />
</root>

<logger name="NHibernate">
    <level value="WARN" />
</logger>

如果这不能解决您的问题,也许您可​​以使用 dotTrace 或 ANTS Profiler 等性能分析工具来识别代码中的潜在瓶颈。这将使您清楚地了解您/NHibernate 代码中的哪些方法花费了大量时间。

Is your application using log4net? If so, you should check your log4net configuration and turn down the amount of data that you're logging from NHibernate.

An example from a project that I'm working on right now: For a query returning 60 rows / objects, logging all NHibernate log messages at DEBUG level to a file increases the total NHProf reported duration from 8ms to around 8000ms!

Example configuration to limit NHibernate output:

<root>
    <level value="ALL" />
    <appender-ref ref="console" />
    <appender-ref ref="trace" />
</root>

<logger name="NHibernate">
    <level value="WARN" />
</logger>

IF this doesn't resolve your problem, perhaps you could use a performance profiling tool like dotTrace or ANTS Profiler to identify potential bottlenecks in your code. This will give you a clear indication of which methods within your / NHibernate's code are taking a lot of time.

极度宠爱 2024-10-17 13:16:46

嗨,我认为您没有找对地方。您不应该查看数据库持续时间等。一旦达到 dB 级别,您就无法对执行执行太多操作。

相反,您应该关注的是向数据库发送了多少查询。您可以通过避免冗余调用或缓存某些查询来以某种方式最小化它们吗?您是只检索与您相关的属性,还是将整个对象加载到内存中然后对其进行处理。

另外,您正在使用什么平台,我也许可以建议您使用更好的工具来识别应用程序中的瓶颈。

希望有帮助。

Hi I dont think you are looking at the right place. You shouldnt be looking at the database duration etc. You cannot do much with the execution once it gets to the dB lvl.

Instead what you should be concentrating on is how many queries do you send to the db. Can you minimise them somehow by avoiding redundant calls or caching some query. Are you retrieving only the properties that concern you or are you loading up an entire object into memory and then working on it.

Also what platform are you working on, I might be able to suggest better tools for you to use to identify bottle neck in your app.

Hope that helps.

南城旧梦 2024-10-17 13:16:46

我确实不知道这一点,但我总是假设总持续时间增加了构建 SQL 查询以及在数据检索时使用原始数据构建实体的所有 NHibernate 开销。

也许您的实体的构建过程非常缓慢?您的实体构造函数中是否有一些广泛的处理?任何 IO 操作、日志记录、额外的数据库访问、网络使用...

祝你好运

I don't know it for a fact but I always assumed that the Total duration adds all the NHibernate overhead of constructing the SQL query, and upon data retrieval constructing the entities with the raw data.

Perhaps the construction process with your entities is very slow? Do you have some extensive processing in your entities constructors? any IO operations, logging, additional DB access, network usage...

Good luck

束缚m 2024-10-17 13:16:46

第一个结果是执行和从数据库检索结果所花费的时间。
第二个结果是 NHibernate 将相应实体加载到内存中所花费的时间。

我现在正在从事一个项目,该项目使用一个非常大的实体(几乎 100 列/字段)。如果我尝试加载几千个,也将需要几秒钟。
然而,sql-query 将在几毫秒内返回实体 ID 列表。但是,如果您的实体是大型或复杂的对象,则将这些 id 实际加载到相应的实体中会产生额外的开销(请参阅上面的帖子)。

您收到有关生成的查询的任何警报吗? NHibernate Profiler 中持续时间旁边的列。

此致,

马蒂亚斯

The first result is the time it took to execute and retrieve the result from the DB.
The second result is the time it takes NHibernate to load the corresponding entities in memory.

Im working in a project right now which utilizes a very large entity (almost 100 columns/fields). If i try to load a couple of thousand it will also take a few seconds.
However, the sql-query will return the list of entity-ids in a few milliseconds. But to actually load these ids into the corresponding entities, generates extra overhead if your entites are large or complex object (see the post above).

Do you get any alerts for the generated queries? The column right next to Duration in NHibernate Profiler.

Best regards,

Mattias

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