LATENCY DOCTOR 是 Redis 自带的「延迟医生」:它读取延迟监控记录下来的事件,输出一份带建议的文字报告。这篇不评价建议好不好,只做一件事:让它在受控条件下报告,对照我制造的事件,看它的输出与什么对应、什么情况下不会出现。
Dave, I have observed latency spikes in this Redis instance. You don't mind talking about it, do you Dave? 1. command: 2 latency spikes (average 55ms, mean deviation 44ms, period 2.50 sec). Worst all time event 100ms. 2. aof-fsync-always: 1 latency spikes (average 9ms, mean deviation 0ms, period 6.00 sec). Worst all time event 9ms. I have a few advices for you: - Your current Slow Log configuration only logs events that are slower than your configured latency monitor threshold. Please use 'CONFIG SET slowlog-log-slower-than 5000'. - Check your Slow Log to understand what are the commands you are running which are too slow to execute. Please check https://redis.io/commands/slowlog for more information. - Your fsync policy is set to 'always'. It is very hard to get good performances with such a setup, if possible try to relax the fsync policy to 'onesec'. - Deleting, expiring or evicting (because of maxmemory policy) large objects is a blocking operation. If you have very large objects that are often deleted, expired, or evicted, try to fragment those objects into multiple smaller objects.
报告分两块:先是「观察到的事件」(事件名、尖峰次数、平均值、平均偏差、周期、历史最大值),然后是根据这些事件生成的「建议」。命令类事件会提示查慢日志并把慢日志阈值与监控阈值对齐(CONFIG SET slowlog-log-slower-than 5000);aof-fsync-always 会提示放宽 fsync 策略(报告里把 everysec 写成了 onesec);最后一条是关于大对象删除的通用提示。这些建议是服务器的通用规则,不是根据你的具体负载算出来的。
1) 1) "command" 2) (integer) 1790706093 3) (integer) 11 4) (integer) 100 2) 1) "aof-fsync-always" 2) (integer) 1790706090 3) (integer) 9 4) (integer) 9
我制造了 DEBUG SLEEP、KEYS、BGSAVE、BGREWRITEAOF 和带 fsync 的 SET,LATENCY LATEST 里只有两类事件:command(慢命令)与 aof-fsync-always。fork 的耗时(这台机器上约几毫秒)没有超过 5 ms 阈值,所以没有 fork 事件——第 66 篇量过 fork 的停顿,这里能不能记录取决于阈值。LATEST / HISTORY / GRAPH 的细节见第 98 篇。
阈值 100 ms,DEBUG SLEEP 0.05 之后 LATENCY LATEST = []
再 DEBUG SLEEP 0.15 之后 LATENCY LATEST = [('command', 151)]把 latency-monitor-threshold 调到 100 ms:50 ms 的阻塞不被记录,150 ms 的才被记录(151 ms)。0 表示关闭。所以「LATENCY DOCTOR 说没问题」可能只是「没有超过阈值的事件」。