什么是慢查询

和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,这样可减少队列移除的频率。

127.0.0.1:6379> config get slowlog-log-slower-than
1) "slowlog-log-slower-than"
2) "10000"
127.0.0.1:6379> config get slowlog-max-len
1) "slowlog-max-len"
2) "128"

可以用config set对这两个参数进行调整,或者在配置文件中设置。

################################## SLOW LOG ###################################

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

慢查询命令

语法:slowlog subcommand [argument]

如,进行查询慢查询、获取慢查询记录的数量、重置慢查询日志等操作:

192.168.10.38:9001> slowlog get
(empty list or set)
192.168.10.38:9001> slowlog get 10
(empty list or set)
192.168.10.38:9001> slowlog len
(integer) 0
192.168.10.38:9001> slowlog reset
OK

关注下面的微信公众号,回复 “答案” 获取全套Redis面试题及答案。

Redis 如何分析慢查询操作?的更多相关文章

  1. MongoDB源码分析——mongod数据查询操作

    源码版本为MongoDB 2.6分支 Edit mongod数据查询操作 在mongod的初始化过程中说过,服务端接收到客户端消息后调用MyMessageHandler::process函数处理消息. ...

  2. [转]Redis实现分析

    Redis实现分析 浏览次数:1018次 KITERUNNER_T 2014年10月19日 字号: 大 中 小 分享到: QQ空间 新浪微博 腾讯微博 人人网 豆瓣网 开心网 更多 1   1 环境准 ...

  3. Redis源代码分析(一)--Redis结构解析

    从今天起,本人将会展开对Redis源代码的学习,Redis的代码规模比較小,很适合学习,是一份很不错的学习资料,数了一下大概100个文件左右的样子,用的是C语言写的.希望终于能把他啃完吧,C语言好久不 ...

  4. redis场景分析的很到位

    链接:http://www.zhihu.com/question/19829601/answer/88069207来源:知乎 1. MySql+Memcached架构的问题 实际MySQL是适合进行海 ...

  5. 双汇大数据方案选型:从棘手的InfluxDB+Redis到毫秒级查询的TDengine

    双汇发展多个分厂的能源管控大数据系统主要采用两种技术栈:InfluxDB/Redis和Kafka/Redis/HBase/Flink,对于中小型研发团队来讲,无论是系统搭建,还是实施运维都非常棘手.经 ...

  6. Redis性能分析思路

    Redis性能分析有几个大的方向.分别是 (1)基准对比 (2)配置优化 (3)数据持久化 (4)键值优化 (5)缓存淘汰 (6)Redis集群 基准对比 在没有业务实例运行的情况下,在服务器上通过测 ...

  7. MySQL(三) 数据库表的查询操作【重要】

    序言 1.MySQL表操作(创建表,查询表结构,更改表字段等), 2.MySQL的数据类型(CHAR.VARCHAR.BLOB,等), 本节比较重要,对数据表数据进行查询操作,其中可能大家不熟悉的就对 ...

  8. Redis 对String数据类型的操作

    Redis的 Strings 数据结构是简单的key-value类型,value其实不仅是String,也可以是数字.使用Strings类型,你可以完全实现目前 Memcached 的功能,并且效率更 ...

  9. day 42 mycql 查询操作,重点中的重点

    数据库的查询操作是重点中的重点,最核心的内容就是它! 在查询时关键字的定义顺序: select distinct(select-list) from (left-table) (type-join) ...

随机推荐

  1. 3,postman的变量写法和collection

    1,环境变量和全局变量的添加和引用 pm.globals.get("variable_key");可以引用环境变量 2,collection的使用 当在tests中使用文件变量的时 ...

  2. 堆&栈的理解(转)

    (摘自:http://www.cnblogs.com/likwo/archive/2010/12/20/1911026.html) C++中堆和栈的理解 内存分配方面: 堆: 操作系统有一个记录空闲内 ...

  3. mysql_事物

    1) set autocommit=0  关闭自动提交   插入修改,只有commit 才最终存入 2) start transaction   commit/rollback 3) show var ...

  4. OO第二单元单元总结

    总述 OO的第二单元主题是电梯调度,与第一单元注重对数据的输入输出的处理.性能的优化不同,第二单元的重心更多的是在线程安全与线程通信上.这此次单元实验之前,我并未对线程有过了解,更谈不上“使用经验”, ...

  5. 跟踪SQL

    在数据库中,找到以下页面,并选择事件中的Tsql下的bath...与stm...

  6. 前端页面播放 rtmp 流与 flv 格式视频文件

    技术 :angular/cli , html5 , typescript , scss ,es 6 ... 项目类型:直播视频与视频回放 使用到 插件 : videojs + ckplayer 遇到的 ...

  7. Windows端口开放

    1.查看:cmd->netstat -na: 2.测试:cmd->telnet [ip] [port]: 3.开启:防火墙新建规则.

  8. sequence测试中的使用

    1. create sequence : create sequence TEST_SEQUENCE minvalue 1 maxvalue 1000000000 start with 1 incre ...

  9. 导出mysql的表格内容到txt文件

    操作流程: $ mysql -uroot -p mysql> use foo; mysql> select * from userinfo into outfile '/var/lib/m ...

  10. ExtJS中listener方法和handler方法的区别

    listener方法和handler方法的区别在文档中的说明的太玄乎了,看不懂 listeners监听能够对一个click Event事件添加任意多个的事件响应处理函数 而handler处理只能够通过 ...