且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

2.4 慢操作日志

更新时间:2022-08-17 13:44:23

像SORT、LREM、SUNION等操作在大对象上会非常耗时,使用时要注意参照官方API上每个命令的算法复杂度。用前面介绍过的慢操作日志监控操作的执行时间。就像主流数据库提供的慢SQL日志一样,Redis也提供了记录慢操作的日志。注意这部分日志只会计算纯粹的操作耗时。
slowlog-log-slower-than设置慢操作的阈值,slowlog-max-len设置保存个数,因为慢操作日志与延迟记录一样,都是保存在内存中的:
  1. 127.0.0.1:6379> config set slowlog-log-slower-than 500
  2. OK 
  3. 127.0.0.1:6379> debug sleep 1
  4. OK
  5. (0.50s)
  6. 127.0.0.1:6379> debug sleep .6
  7. OK
  8. 127.0.0.1:6379> slowlog get 10
  9. 1) 1) (integer) 2
  10.    2) (integer) 1439369937
  11.    3) (integer) 473178
  12.    4) 1) "debug"
  13.       2) "sleep"
  14.       3) ".6"
  15. 2) 1) (integer) 1
  16.    2) (integer) 1439369821
  17.    3) (integer) 499357
  18.    4) 1) "debug"
  19.       2) "sleep"
  20.       3) "1"
  21. 3) 1) (integer) 0
  22.    2) (integer) 1439365058
  23.    3) (integer) 417846
  24.    4) 1) "debug"
  25.       2) "sleep"
  26.       3) "1"
复制代码

输出的四列的含义分别是:记录的自增ID、命令执行时的时间戳、命令的执行耗时(ms)、命令的内容。注意上面的DEBUG命令并没有包含休眠时间,而只是命令的处理时间。





本文作者:geelou
本文来自云栖社区合作伙伴rediscn,了解相关信息可以关注redis.cn网站。