加入收藏 | 设为首页 | 会员中心 | 我要投稿 河北网 (https://www.hebeiwang.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程 > 正文

Redis怎样说明慢查询操纵?

发布时间:2018-09-14 13:37:49 所属栏目:编程 来源:不羁码农
导读:9月15日技能沙龙 | 与东华软件、AWS、京东金融、饿了么四位大咖切磋精准运维! 什么是慢查询 和mysql的慢SQL日记说明一样,redis也有相同的成果,来辅佐定位一些慢查询操纵。 Redis slowlog是Redis用来记录查询执行时刻的日记体系。 查询执行时刻指的是不包
9月15日技能沙龙 | 与东华软件、AWS、京东金融、饿了么四位大咖切磋精准运维!

Redis怎样说明慢查询操纵?

什么是慢查询

和mysql的慢SQL日记说明一样,redis也有相同的成果,来辅佐定位一些慢查询操纵。

Redis slowlog是Redis用来记录查询执行时刻的日记体系。

查询执行时刻指的是不包罗像客户端相应(talking)、发送回覆等IO操纵,而单单是执行一个查询呼吁所淹灭的时刻。

其它,slow log生涯在内存内里,读写速率很是快,因此你可以安心地行使它,不必担忧由于开启slow log而侵害Redis的速率。

慢查询参数

起首来存眷下慢日记说明对应的两个参数:

1、slowlog-log-slower-than:预设阀值,即记录高出几多时刻的记录,默以为10000微秒,即10毫秒。

2、slowlog-max-len:记录慢查询的条数,默以为128条,当高出配置的条数时最早进入行列的将被移除。线上提议增大数值,如:1000,这样可镌汰行列移除的频率。

  1. 127.0.0.1:6379> config get slowlog-log-slower-than  
  2. 1) "slowlog-log-slower-than"  
  3. 2) "10000"  
  4. 127.0.0.1:6379> config get slowlog-max-len  
  5. 1) "slowlog-max-len"  
  6. 2) "128"  

可以用config set对这两个参数举办调解,可能在设置文件中配置。

  1. ################################## SLOW LOG ###################################  
  2. # The Redis Slow Log is a system to log queries that exceeded a specified  
  3. # execution time. The execution time does not include the I/O operations  
  4. # like talking with the client, sending the reply and so forth,  
  5. # but just the time needed to actually execute the command (this is the only  
  6. # stage of command execution where the thread is blocked and can not serve  
  7. # other requests in the meantime). 
  8. #  
  9. # You can configure the slow log with two parameters: one tells Redis  
  10. # what is the execution time, in microseconds, to exceed in order for the  
  11. # command to get logged, and the other parameter is the length of the  
  12. # slow log. When a new command is logged the oldest one is removed from the  
  13. # queue of logged commands.   
  14. # The following time is expressed in microseconds, so 1000000 is equivalent  
  15. # to one second. Note that a negative number disables the slow log, while  
  16. # a value of zero forces the logging of every command.  
  17. slowlog-log-slower-than 10000   
  18. # There is no limit to this length. Just be aware that it will consume memory.  
  19. # You can reclaim memory used by the slow log with SLOWLOG RESET.  
  20. slowlog-max-len 128 

慢查询呼吁

语法:slowlog subcommand [argument]

如,举办查询慢查询、获取慢查询记录的数目、重置慢查询日记等操纵:

  1. 192.168.10.38:9001> slowlog get  
  2. (empty list or set)  
  3. 192.168.10.38:9001> slowlog get 10  
  4. (empty list or set)  
  5. 192.168.10.38:9001> slowlog len   
  6. (integer) 0  
  7. 192.168.10.38:9001> slowlog reset  
  8. OK   

【编辑保举】

  1. 值得看|30道Redis口试题,口试官能问的都被我找到了
  2. 怎样行使Redis构建轻量级微处事
  3. MySQL数据库怎样去掉数据库中一再记录?
  4. 怎样行使Redis做MySQL的缓存
  5. 阿里P8架构师谈:MySQL慢查询优化、索引优化、以及表等优化总结
【责任编辑:庞桂玉 TEL:(010)68476606】
点赞 0

(编辑:河北网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读