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,这样可减少队列移除的频率。
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 如何分析慢查询操作?的更多相关文章
- MongoDB源码分析——mongod数据查询操作
源码版本为MongoDB 2.6分支 Edit mongod数据查询操作 在mongod的初始化过程中说过,服务端接收到客户端消息后调用MyMessageHandler::process函数处理消息. ...
- [转]Redis实现分析
Redis实现分析 浏览次数:1018次 KITERUNNER_T 2014年10月19日 字号: 大 中 小 分享到: QQ空间 新浪微博 腾讯微博 人人网 豆瓣网 开心网 更多 1 1 环境准 ...
- Redis源代码分析(一)--Redis结构解析
从今天起,本人将会展开对Redis源代码的学习,Redis的代码规模比較小,很适合学习,是一份很不错的学习资料,数了一下大概100个文件左右的样子,用的是C语言写的.希望终于能把他啃完吧,C语言好久不 ...
- redis场景分析的很到位
链接:http://www.zhihu.com/question/19829601/answer/88069207来源:知乎 1. MySql+Memcached架构的问题 实际MySQL是适合进行海 ...
- 双汇大数据方案选型:从棘手的InfluxDB+Redis到毫秒级查询的TDengine
双汇发展多个分厂的能源管控大数据系统主要采用两种技术栈:InfluxDB/Redis和Kafka/Redis/HBase/Flink,对于中小型研发团队来讲,无论是系统搭建,还是实施运维都非常棘手.经 ...
- Redis性能分析思路
Redis性能分析有几个大的方向.分别是 (1)基准对比 (2)配置优化 (3)数据持久化 (4)键值优化 (5)缓存淘汰 (6)Redis集群 基准对比 在没有业务实例运行的情况下,在服务器上通过测 ...
- MySQL(三) 数据库表的查询操作【重要】
序言 1.MySQL表操作(创建表,查询表结构,更改表字段等), 2.MySQL的数据类型(CHAR.VARCHAR.BLOB,等), 本节比较重要,对数据表数据进行查询操作,其中可能大家不熟悉的就对 ...
- Redis 对String数据类型的操作
Redis的 Strings 数据结构是简单的key-value类型,value其实不仅是String,也可以是数字.使用Strings类型,你可以完全实现目前 Memcached 的功能,并且效率更 ...
- day 42 mycql 查询操作,重点中的重点
数据库的查询操作是重点中的重点,最核心的内容就是它! 在查询时关键字的定义顺序: select distinct(select-list) from (left-table) (type-join) ...
随机推荐
- shapefile添加字段 设置文件名为字段内容
转眼间,这一年又结束了,再记录一点知识吧 同事说他有好多shapefile,想给每个shapefile添加一字段,并设置该字段的内容为shapefile文件名,想着用arcpy实现,于是有了下面的代码 ...
- java将图片传为设定编码值显示(可做刺绣)
import java.awt.Color; import java.awt.image.BufferedImage;import java.io.File;import java.io.IOExce ...
- JS獲取URL的參數
function GetQueryString(name) { var reg = new RegExp("(^|&)"+ name +"=([^&]*) ...
- python搭建服务器时nginx的有关问题
最近在学习Python服务器搭建的内容,网上大多是Windows环境下的,由于我使用的是Mac,为了不想装双系统折腾,就只好一步步采坑了.比较基础的我一步步记录下来, 1.安装nginx: brew ...
- ThinkPhp5 出现访问出现 No input file specified. 问题
今天复习一下ThinkPhp5,在官网下载了核心版,windows下配置了虚拟域名之后出现了神奇的现象 如下图 直接访问域名能访问到index模块下的index控制器下的index方法 但是我输入完整 ...
- centos6安装oracle时运行./runInstaller无法弹出图形界面
首先确保安装oracle的机器上安装了图形化界面. 1.利用xmanager登录到安装oracle的服务器上(直接用root用户登录) 2.运行 export DISPLAY=你的本机地址:0.0 3 ...
- Notes on Operating System
- Spring核心
方法区与常量池 BeanFactoryPostProcessor与BeanPostProcessor使用 创建pc过程 https://www.liangzl.com/get-article-deta ...
- 使用IDEA进行版本控制
1.使用IDEA进行版本控制 创建git repository add-添加到暂存区 commit-提交到本地库 push-推送指定远程库(自己的) idea上的pull指的是合并(merge),并非 ...
- bzoj1038(半平面交)
#include<iostream> #include<cstring> #include<cmath> #include<cstdio> #inclu ...