0%

Redis慢查询

Redis执行一条命令有四个过程:发送命令、命令排队、命令执行、返回结果,整个过程是一个往返时间(Round Trip Time,简称RTT)。

一、慢查询

  1. 默认配置
1
2
slowlog-log-slower-than 10000
slowlog-max-len 128
  1. 查看配置config get slow*

  2. 动态修改配置config set slowlog-max-len 100

  3. 慢查询现相关命令

    • slowlog get n:获取慢查询队列
    • slowlog len:获取慢查询队列长度
    • slowlog reset:清空慢查询队列
  4. redis快的原因

    • 完全基于内存
    • 数据结构简单,对数据操作也简单
    • 使用多路I/O复用模型
      • 其他模型
        • 多进程单线程模型:nginx
        • 单进程多线程模型:memcached

二、超时排查

  1. 判断标准

    • –latency--intrinsic-latency num
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19


>./redis-cli --intrinsic-latency 100
Max latency so far: 1 microseconds.
Max latency so far: 10 microseconds.
Max latency so far: 12 microseconds.
Max latency so far: 56 microseconds.
Max latency so far: 152 microseconds.
Max latency so far: 250 microseconds.
Max latency so far: 1519 microseconds.
Max latency so far: 5605 microseconds.
Max latency so far: 10096 microseconds.
Max latency so far: 30747 microseconds.
Max latency so far: 31746 microseconds.

Max latency so far: 46306 microseconds.

1441320883 total runs (avg latency: 0.0694 microseconds / 69.38 nanoseconds per run).
Worst run took 667418x longer than the average latency.
  1. 如何避免

三、参考

  1. 参考一
  2. 参考二
  3. 参考三