什么是"同步块"和用于降低计数的提示 [英] What is a "Sync Block" and tips for reducing the count

查看:157
本文介绍了什么是"同步块"和用于降低计数的提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个Windows窗体应用程序使用(第三方)的ActiveX控件,而在.NET CLR内存下的.NET性能对象一起被注意到,在使用同步块的数量正在不断增加(随着内存使用情况),即使我们的应用程序正坐在那里无所事事。

We have a Windows Forms application that uses a (third party) ActiveX control, and are noticing in the .NET performance objects under ".NET CLR Memory" that the number of "Sync Blocks" in use is constantly increasing (along with increasing memory usage), even though our application is sitting there idle.

有关水槽块计数状态内置的解释:

The built-in explanation for the sink block count states:

这计数器显示使用中的同步块的当前数目。同步块是分配用于存储同步信息每个对象的数据结构。同步块抱被管理对象的弱引用并需要由垃圾收集器进行扫描。同步块并不局限于存储的同步信息,并且还可以存储COM互操作的元数据。此计数器旨在表明大量使用同步原语的性能问题。

This counter displays the current number of sync blocks in use. Sync blocks are per-object data structures allocated for storing synchronization information. Sync blocks hold weak references to managed objects and need to be scanned by the Garbage Collector. Sync blocks are not limited to storing synchronization information and can also store COM interop metadata. This counter was designed to indicate performance problems with heavy use of synchronization primitives.

同步块数似乎得到,当我们切换复位不同的应用程序,但。究竟是什么原因导致这些来生成,并有哪几种?

The sync block count does seem to get reset when we switch to a different application though. What exactly causes these to get created, and are there any tips for reducing the number of these?

(顺便说一句,这真的是在列表中拼写为汇块为减少这些数目的提示性能计数器。我不知道如果一个错字或管道笑话)

(BTW, it really is spelled "sink block" in the list of performance counters. I'm not sure if its a typo or a plumbing joke)

推荐答案

每当你使用一个锁定等基元锁定 Monitor.Enter 在.NET平台,同步块结构对对象实例初始化被锁定。如在定义中所述,这些块可以容纳更多的信息,如对象的哈希码和COM互操作信息

Everytime you use a locking primitive such as lock or Monitor.Enter in the .NET platform, a sync block structure is initialized against the object instance to be locked. As stated in the definition, these blocks can hold more information such as the object's hash code and COM interop information.

由于这些块在什么可以存储的限制,在访问块同时使争用这反过来导致对象首标中的内容成为一个索引由CLR管理系统范围同步块的表。 CLR的是能够将这些同步块回收作为当物需要他们。

Since these blocks are limited in what can be stored, accessing the blocks simultaneously causes contention which in turn causes the object header's contents to become an index into a table of system-wide sync blocks managed by the CLR. The CLR is able to recycle these sync block as and when object need them.

锁定对象在等待一个系统内核对象之前总是会带来CPU纺纱。每当分配CPU自旋不是在线北京允许显示器以获得临界区锁,一个系统自动重置事件句柄将被创建和对它的引用将被放置在相应的同步块。然后等待该事件处理其他线程将在事件处理阻塞,直到拥有线程触发了事件处理的版本。

Locking on an object always incurs CPU spinning before waiting on a system kernel object. Whenever the allocated CPU spin is not satisified for allowing a monitor to acquire the critical section lock, an system auto-reset event handle will be created and a reference to it will be put in the associated sync block. Other threads waiting on this event handle will then block on the event handle until the owning thread has triggered the event handle's release.

因此​​,如果该计数器不断增加,这是一个迹象,过多的线程都在争上一个或多个对象锁和这些锁可能永远会得到释放。

Therefore, if this counter constantly increases, it is a sign that too many threads are on contention for a lock on one or more objects and these locks might never be getting released.

这篇关于什么是"同步块"和用于降低计数的提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆