MongoDB flow control
2023-10-27 15:56 abce 阅读(229) 评论(0) 收藏 举报从 MongoDB 4.2 开始,管理员可以限制主节点的写入速度,目的是将多数提交的延迟保持在可配置的最大值 flowControlTargetLagSeconds 以下。
默认情况下, flow control 是启用的。
启用 flow control 后,当延迟时间接近 flowControlTargetLagSeconds 时,主节点上的写操作必须先获得票据,然后才能加锁应用写操作。通过限制每秒签发的票据数量, flow control 机制试图将延迟保持在目标值以下。
查看 flow control 的状态
> db.serverStatus().flowControl
{
enabled: true,
targetRateLimit: 1000000000,
timeAcquiringMicros: Long("134209790"),
locksPerKiloOp: 4,
sustainerRate: 1000,
isLagged: false,
isLaggedCount: 19,
isLaggedTimeMicros: Long("18991175")
}
1.运行 rs.printSecondaryReplicationInfo() 确认是否有节点发生了延迟
> rs.printSecondaryReplicationInfo()
source: 11.12.10.28:27017
{
syncedTo: 'Fri Oct 27 2023 15:24:46 GMT+0800 (China Standard Time)',
replLag: '0 secs (0 hrs) behind the primary '
}
---
source: 11.12.10.30:27017
{
syncedTo: 'Fri Oct 27 2023 15:24:46 GMT+0800 (China Standard Time)',
replLag: '0 secs (0 hrs) behind the primary '
}
---
source: 192.168.16.15:27017
{
syncedTo: 'Fri Oct 27 2023 15:24:46 GMT+0800 (China Standard Time)',
replLag: '100 secs (0 hrs) behind the primary '
}
2.运行 serverStatus 命令并使用 flowControl.isLagged 值确定副本集是否已遇到 flow control:
> db.runCommand( { serverStatus: 1 } ).flowControl.isLagged
false
如果结果为false,就需要去副本节点上查看延迟的原因了。

浙公网安备 33010602011771号