禁用锁升级是否会给数据 mdf 带来更多压力?

Does disabling lock escalation put more stress on the data mdf?

我们有一个大型多用途应用程序,在许多 table 上遇到 OBJECT 和 PAGE 块。我们无法重新考虑设计,但需要减少影响客户端机器性能的块。 我一直在考虑禁用一个 table 上的锁升级,但需要知道它会给其他资源带来什么样的压力。磁盘 i/o 已经紧张。与自动 table 锁相比,额外的单个锁需要更多 i/o 吗?它会影响我们的系统数据库而不是我们的应用程序数据库吗? 我们不做完整的 table updates/reads。每个请求只会处理 table.

的一小部分

We have a large multi-use application suffering from OBJECT and PAGE blocks on a number of tables.

...

The disk i/o is already strained. Will additional, individual locks require more i/o than the automatic table locks?

你误解了锁升级,从你问题中我加粗的部分可以清楚地看出这一点。

锁升级变为 from rows to tablefrom pages to table(我排除了分区,因为这不是你的情况),所以如果现在你有 页面锁 它是 不锁升级

锁定粒度由服务器选择,除非您使用提示(rowlockpaglock),如果它选择 page locks,则不会升级。如果它然后删除所有 page locks 并用 table lock 替换它们,则意味着 lock escalation 发生了。

第二个错误是你认为锁与IO有关。这不是真的。锁保存在内存中,与读取无关。您可以查看这篇文章以了解 CPU usagequery duration 如何在锁更细粒度时增加:Why ROWLOCK Hints Can Make Queries Slower and Blocking Worse in SQL Server.

您应该了解导致锁升级的原因。

Lock Escalation Thresholds

Lock escalation is triggered when lock escalation is not disabled on the table by using the ALTER TABLE SET LOCK_ESCALATION option, and when either of the following conditions exists:

  • A single Transact-SQL statement acquires at least 5,000 locks on a single nonpartitioned table or index.
  • A single Transact-SQL statement acquires at least 5,000 locks on a single partition of a partitioned table and the ALTER TABLE SET LOCK_ESCALATION option is set to AUTO.
  • The number of locks in an instance of the Database Engine exceeds memory or configuration thresholds.

Lock Escalation (Database Engine)

因此,如果您达到每个语句阈值 5,000 个锁,您应该将您的操作拆分为更小的批次。

如果你有内存压力,禁用锁升级会让你的情况更糟。

更新

我在书中找到了关于锁的描述 Microsoft SQL Server 2012 Internals (Developer Reference)by Kalen Delaney (Author),‎ Bob Beauchemin (Author),‎ Conor Cunningham (Author),‎ Jonathan Kehayias (Author),‎ Paul S. Randal (Author),‎ Benjamin Nevarez (Author

Locks aren’t on-disk structures. You won’t find a lock field directly on a data page or a table header, and the metadata that keeps track of locks is never written to disk. Locks are internal memory structures: They consume part of the memory used for SQL Server. A lock is identified by lock resource, which is a description of the resource that’s locked (a row, index key, page, or table). To keep track of the database, the type of lock, and the information describing the locked resource, each lock requires 64 bytes of memory on a 32-bit system and 128 bytes of memory on a 64-bit system. This 64-byte or 128-byte structure is called a lock block. ... The lock manager maintains a lock hash table. Lock resources, contained within a lock block, are hashed to determine a target hash slot in the hash table. All lock blocks that hash to the same slot are chained together from one entry in the hash table. Each lock block contains a 15-byte field that describes the locked resource. The lock block also contains pointers to lists of lock owner blocks. Each of the three states has a separate list for lock owners.

希望对您有所帮助。