.NET 锁定性能计数器差异

发布于 2025-01-01 13:18:22 字数 385 浏览 0 评论 0原文

“.NET CLR LocksAndThreads”类别中的“争用总数”和“队列长度峰值”窗口性能计数器有什么区别? MSDN 文档可在此处获取:http://msdn.microsoft.com/en-us /library/zf749bat.aspx

我认为我的困惑在于“尝试获取锁失败的线程数”与“自应用程序启动以来等待获取托管锁的线程总数”之间的差异。从本质上讲,等待获取锁(我将其解释为当您尝试获取锁时其他人正在持有它)与尝试获取锁失败之间有什么区别?我唯一能想到的与如何尝试锁定获取有关,例如 Monitor.TryEnter 与 Monitor.Enter。

What is the difference between the "Total # of Contentions" and "Queue Length Peak" windows performance counters in the ".NET CLR LocksAndThreads" category? MSDN Documentation is available here: http://msdn.microsoft.com/en-us/library/zf749bat.aspx.

I think my confusion is about the difference between "the number of threads that tried to acquire a lock unsuccessfully" vs "the total number of threads that waited to acquire a managed lock since the application started." In essence, what is the difference between waiting to acquire a lock, which I interpret as meaning someone else is holding it when you try to acquire it, and trying to acquire a lock unsuccessfully?? The only thing I can think of would be related to how lock acquisition is attempted, e.g. Monitor.TryEnter vs. Monitor.Enter.

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

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

发布评论

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

评论(1

缺⑴份安定 2025-01-08 13:18:22

当尝试获取锁时我会想到 3 种情况:
a) 资源没有被其他实体锁定,立即获取
b) 资源被锁定,但按时释放,延迟获取
c) 资源被锁定,但未按时释放,获取超时

争用总数 - 场景总数 (c)
队列长度峰值 - 在任何给定时间处于状态 (b) 的线程最多

I would think of 3 scenarios when trying to acquire lock:
a) resource no locked by other entity, acquired immediately
b) resource locked, but released on time, acquired with delay
c) resource locked, but not released on time, acquisition times out

Total # of Contentions - total of scenario (c)
Queue Length Peak - at any given time the most threads in state (b)

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