文档首页
MySQL 8.4 参考手册
8.4 中文镜像

MySQL 8.4 参考手册 · 中文镜像

正文为中文,英文原文默认隐藏。点击任意中文段落即可展开 / 收起对应英文原文。

打开官方英文原文 ↗

译文由机器翻译生成,仅供理解参考;有疑问请以官方英文原文为准。

中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 73%

17.7.6 事务调度17.7.6 Transaction Scheduling

InnoDB 使用争用感知事务调度(CATS)算法来优先处理正在等待锁的事务。当多个事务在等待同一对象的锁时,CATS 算法决定哪个事务先获得锁。InnoDB uses the Contention-Aware Transaction Scheduling (CATS) algorithm to prioritize transactions that are waiting for locks. When multiple transactions are waiting for a lock on the same object, the CATS algorithm determines which transaction receives the lock first.

CATS 算法通过分配调度权重来优先处理等待事务,该权重是根据事务阻塞的事务数量计算的。例如,如果两个事务在等待同一对象的锁,阻塞其他事务最多的事务会被分配更高的调度权重。如果权重相等,则优先处理等待时间最长的事务。The CATS algorithm prioritizes waiting transactions by assigning a scheduling weight, which is computed based on the number of transactions that a transaction blocks. For example, if two transactions are waiting for a lock on the same object, the transaction that blocks the most transactions is assigned a greater scheduling weight. If weights are equal, priority is given to the longest waiting transaction.

您可以通过查询信息模式 INNODB_TRX 表中的 TRX_SCHEDULE_WEIGHT 列来查看事务调度权重。权重仅针对等待中的事务进行计算。等待中的事务是指处于 LOCK WAIT 事务执行状态的事务,如 TRX_STATE 列所报告的那样。未等待锁的事务报告的 TRX_SCHEDULE_WEIGHT 值为 NULL。You can view transaction scheduling weights by querying the TRX_SCHEDULE_WEIGHT column in the Information Schema INNODB_TRX table. Weights are computed for waiting transactions only. Waiting transactions are those in a LOCK WAIT transaction execution state, as reported by the TRX_STATE column. A transaction that is not waiting for a lock reports a NULL TRX_SCHEDULE_WEIGHT value.

INNODB_METRICS 计数器用于监控代码级事务调度事件。有关使用 INNODB_METRICS 计数器的信息,请参见 第 17.15.6 节,“InnoDB INFORMATION_SCHEMA Metrics 表”。INNODB_METRICS counters are provided for monitoring of code-level transaction scheduling events. For information about using INNODB_METRICS counters, see Section 17.15.6, “InnoDB INFORMATION_SCHEMA Metrics Table”.

  • lock_rec_release_attempts

    尝试释放记录锁的次数。一次尝试可能释放零个或多个记录锁,因为在单个结构中可能有零个或多个记录锁。The number of attempts to release record locks. A single attempt may lead to zero or more record locks being released, as there may be zero or more record locks in a single structure.

  • lock_rec_grant_attempts

    授予记录锁的尝试次数。一次尝试可能会授予零个或多个记录锁。The number of attempts to grant record locks. A single attempt may result in zero or more record locks being granted.

  • lock_schedule_refreshes

    分析等待图以更新计划事务权重的次数。The number of times the wait-for graph was analyzed to update the scheduled transaction weights.