Redis分析慢查询操作的实例教程
Redis 操作 查询 分析 实例教程
2023-06-13 09:19:50 时间
慢查询的作用:通过慢查询分析,找到有问题的命令进行优化。
和mysql的慢SQL日志分析一样,redis也有类似的功能,来帮助定位一些慢查询操作。
Redis slowlog是Redis用来记录查询执行时间的日志系统。
查询执行时间指的是不包括像客户端响应(talking)、发送回复等IO操作,而单单是执行一个查询命令所耗费的时间。
另外,slow log保存在内存里面,读写速度非常快,因此你可以放心地使用它,不必担心因为开启slow log而损害Redis的速度。
慢查询日志四个属性:
1、第一个字段是每个慢查询唯一标识。
2、处理完命令后的时间戳
3、执行改名了所需要的时间,单位微妙
4、命令的参数列表,是个数组类型
每个慢查询实体的ID都是唯一的,而且不会被重新设置,只会在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
本篇文章到此结束,如果您有相关技术方面疑问可以联系我们技术人员远程解决,感谢大家支持本站!
我想要获取技术服务或软件
服务范围:MySQL、ORACLE、SQLSERVER、MongoDB、PostgreSQL 、程序问题
服务方式:远程服务、电话支持、现场服务,沟通指定方式服务
技术标签:数据恢复、安装配置、数据迁移、集群容灾、异常处理、其它问题
本站部分文章参考或来源于网络,如有侵权请联系站长。
数据库远程运维 Redis分析慢查询操作的实例教程
相关文章
- Redis安全之基线:必须要做的把戏(redis安全基线)
- 使用Redis配置服务器:一步一步指南(redis配置服务器)
- 测试Java操作Redis实例(java测试redis)
- 信息Redis精准查询某用户的信息一探究竟(查询redis中某个用户)
- 快速熟悉Redis Slot查询技巧(查询redis slot)
- 探索Redis的运行主机(查看redis的主机)
- Redis如何使用索引加快查询速度(用redis怎么创建索引)
- 排行榜的新挑战Elasticsearch与Redis的对比(排行榜es与redis)
- 如何通过Redis实现原子操作(如何实现redis事物)
- Redis中的增强命令提升查询效率(增加redis命令)
- 命令行操作Redis实现轻松超越(命令行写redis)
- 查询分析Redis在高并发时慢查询的原因(redis高并发时慢)
- 操作使用Redis集群实现高效单线程操作(redis集群实现单线程)
- 实现高效Redis集群备份的技术研究(redis集群备份对应)
- Redis集群关闭的正确操作(redis集群关闭的命令)
- Redis锁如何实现强大的并发管理(redis锁是如何实现的)
- 使用Redis轻松实现快速转发查询(redis 转发查询)
- 响应加快用Redis进行网页无图片响应加速(redis 网页无图片)
- Redis缩容操作指南(redis缩容教程)