当前位置:网站首页>Redis学习笔记—慢查询分析
Redis学习笔记—慢查询分析
2022-06-23 09:00:00 【爱锅巴】
慢查询日志帮助开发人员定位系统存在的慢操作,慢查询就是系统在命令执行前后计算的每条命令的执行时间,当超过预设阈值,就将这条命令的相关信息(例如:发生时间,耗时,命令的详细信息)记录下来,Redis提供类似的功能
客户端请求的四个执行步骤
1.发送命令——2.排队等待执行——3.执行命令——4.返回结果
慢查询只统计步骤3执行命令的这一步,所以没有慢查询并不等于客户端没有超时的情况
慢查询的配置参数
在redis.conf配置文件中有两个配置项:slowlog-log-slower-than和slowlog-max-len
slowlog-log-slower-than表示预设的阈值,默认为10000微秒(1秒=1000毫秒=1000000微秒),如果一条命令执行时间超过了10000微秒就会被记录放在慢查询日志中
如果slowlog-log-slower-than设置为0就会记录所有的命令,设置为小于0就不会记录任何的命令
slowlog-max-len:Redis使用了一个列表来存储慢查询日志,此配置就是这个列表的最大长度,默认为128条,如果记录多于128条会删除最先插入的数据
如果想要修改配置可以直接在redis客户端进行修改,以slowlog-max-len为例
127.0.0.1:6379> config set slowlog-max-len 512
OK
127.0.0.1:6379> config rewrite
OK
在查看配置文件,发现slowlog-max-len配置已经修改为512了
获取慢查询日志
虽然慢查询日志是存放在Redis内存列表中的,但是Redis并没有暴露这个列表的键,而是通过一组命令来实现对慢查询日志的访问和管理。
slowlog get [n]
查询两条慢查询记录,此处的[n]为选填项,如果不填查询所有,如果填就是查询指定的条数
127.0.0.1:6379> slowlog get "2"
1) 1) (integer) 12
2) (integer) 1552899968
3) (integer) 1000502
4) 1) "migrate"
2) "127.0.0.1"
3) "6379"
4) "a"
5) "1"
6) "1000"
7) "copy"
5) "127.0.0.1:35730"
6) ""
2) 1) (integer) 11
2) (integer) 1552899943
3) (integer) 1000909
4) 1) "migrate"
2) "127.0.0.1"
3) "6379"
4) "a"
5) "0"
6) "1000"
7) "copy"
5) "127.0.0.1:35730"
6) ""
四个主要参数
- 慢查询日志的标识id
- 发生时间戳
- 命令耗时
- 执行命令和参数
获取慢查询列表长度
slowlog len
当前有13条慢查询
127.0.0.1:6379> slowlog len
(integer) 13
清除慢查询列表
slowlog reset
清除当前慢查询列表
127.0.0.1:6379> slowlog len
(integer) 13
127.0.0.1:6379> slowlog reset
OK
127.0.0.1:6379> slowlog len
(integer) 0
边栏推荐
- 在小程序中实现视频通话及互动直播的一种方法
- Why is the easycvr Video Fusion platform offline when cascading with the Hikvision platform? How to solve it?
- “教练,我想打篮球“ —— 给做系统的同学们准备的 AI 学习系列小册
- 4sum of leetcode topic analysis
- [qnx hypervisor 2.2 user manual]5.6.1 silent device during guest shutdown
- JS mask important data of ID card and mobile phone number with * *
- Comprehensive analysis of news capture
- TDesign update weekly report (the first week of January 2022)
- 438. Find All Anagrams in a String
- RGB与CMYK颜色模式
猜你喜欢

986. Interval List Intersections

297. Serialize and Deserialize Binary Tree
![[event registration] sofastack × CSDN jointly held the open source series meetup, which was launched on June 24](/img/e1/97c92290a2a5e68f05cdbd5bf525e8.png)
[event registration] sofastack × CSDN jointly held the open source series meetup, which was launched on June 24

3. caller service call - dapr

General paging (1)

Testing -- automated testing selenium (about API)

测试-- 自动化测试selenium(关于API)

Typora设置图片上传服务
![[learning resources] understand and love mathematics](/img/a3/e1b0915c48c85d17c48a4bee523424.png)
[learning resources] understand and love mathematics

瞄准海外宠物市场,「Grasphand 」做了一款独立于手机的智能追踪产品 | 早期项目
随机推荐
进入小公司的初级程序员要如何自我提高?
TDesign update weekly report (the first week of January 2022)
636. Exclusive Time of Functions
2022.6.22-----leetcode. five hundred and thirteen
Testing -- automated testing selenium (about API)
自定义标签——jsp标签增强
MQTT+Flink实现实时消息的订阅与发布
Leetcode topic analysis group anagrams
[qnx hypervisor 2.2 user manual]6.1 using the QNX hypervisor system
Click Add drop-down box
js 用**遮罩身份证以及手机号的重要数据
How postman does interface testing 1: how to import swagger interface documents
'coach, I want to play basketball!'—— AI Learning Series booklet for system students
528. Random Pick with Weight
Typora设置图片上传服务
@Response
S5P4418裸机编程的实现(替换2ndboot)
2022.6.22-----leetcode.513
297. Serialize and Deserialize Binary Tree
Leetcode topic analysis 3sum closest