Redis如何分析慢查询操作?

数据库 其他数据库 Redis
和mysql的慢SQL日志分析一样,redis也有类似的功能,来帮助定位一些慢查询操作。Redis slowlog是Redis用来记录查询执行时间的日志系统。

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 timein 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   

 

责任编辑:庞桂玉 来源: Java技术栈
相关推荐

2019-09-11 10:23:58

Redis性能存储

2022-03-22 10:52:02

Redis变慢服务器

2020-09-13 13:05:41

MySQL慢查询数据

2021-04-07 10:38:43

MySQL数据库命令

2023-11-30 15:37:37

MySQL数据库

2018-10-12 16:45:10

MySQL查询日志数据库

2010-06-02 13:46:19

MySQL慢查询

2019-09-18 08:06:08

Redis数据库命令

2009-09-16 10:48:32

LINQ查询操作

2022-04-29 15:24:53

Redis存储慢查询

2023-10-16 23:12:02

Redis数据结构

2017-04-01 19:00:25

MySQL慢查询

2022-07-14 14:46:51

数据库SQL系统设计

2010-10-14 15:07:44

MySQL慢查询

2022-10-27 09:42:22

数据库SQL

2021-11-08 06:57:35

Redis架构设计

2022-04-22 14:41:12

美团慢查询数据库

2022-10-21 10:40:08

携程酒店MySQL慢查询

2022-03-16 14:45:18

MySQL慢查询数据库

2020-06-05 09:21:20

MySQL慢查询数据库
点赞
收藏

51CTO技术栈公众号