【Azure Redis 缓存】Azure Cache for Redis 中如何快速查看慢指令情况(Slowlogs)

本文涉及的产品
云数据库 Tair(兼容Redis),内存型 2GB
Redis 开源版,标准版 2GB
推荐场景:
搭建游戏排行榜
简介: 【Azure Redis 缓存】Azure Cache for Redis 中如何快速查看慢指令情况(Slowlogs)

问题描述

当 Azure Redis 服务器负载过高的情况下,使用时就会遇见连接超时,命令超时,IO Socket超时等异常。为了能定位是那些因素引起的,可以参考微软官方文档( 管理 Azure Cache for Redis 的服务器负载 : https://docs.azure.cn/zh-cn/azure-cache-for-redis/cache-best-practices-server-load#avoid-long-running-commands) 开始以下因素的分析:

  1. 值大小 : 可以通过Redis-cli.exe 的bigkeys来进行分析 [redis-cli.exe -h yourcachename.redis.cache.chinacloudapi.cn -p 6379 -a YourAccessKey  --bigkeys ]

 

  1. 避免出现客户端连接高峰 : 可以查看Redis Metrics中的连接数
  2. 内存压力 : 通过查看Redis Metrics中的内存使用量
  3. 避免长时间运行的命令 : 通过Azure Redis门户上的console或者是Redis-cli.exe 来执行 slowlog get 100指令

 

本文就重点演示在Azure Redis门户上的console页面执行 slowlog get 100 指令。

 

问题回答

因为Redis 服务器是单线程系统。 长时间运行的命令(官名:慢指令, Slowlog)可能导致客户端出现延迟或超时,因为服务器在忙于处理长时间运行的命令时无法响应任何其他请求。那么,如何来查看慢指令呢?

 

第一步: 登录Azure门户,选择需要查看的Redis服务,进入Console页面

第二步:在Console命令页输入:slowlog get 100

  • slowlog get 100: 获取当前Redis服务中所记录的慢指令信息,每一个指令包含六部分内容,id,unix时间,指令执行时间(ms 微秒), 指令内容,客户端IP:端口,客户端机器名。
  • slowlog len : 返回当前Redis服务器中所记录的慢指令日志中所记录指令数
  • slowlog reset :清空当前慢指令记录

 

指令输出示例:

Welcome to secure redis console!
This console connects to your live redis server and all commands are run on the server.
WARNING: Use expensive commands with caution as they can impact your server load!
>slowlog get 100
1) 1) (integer) 16
    2) (integer) 1639993957
    3) (integer) 10012
    4) 1) "GET"
       2) "key:__rand_int__"
    5) "167.220.233.137:14835"
    6) ""
2) 1) (integer) 15
    2) (integer) 1639993727
    3) (integer) 10195
    4) 1) "GET"
       2) "key:__rand_int__"
    5) "167.220.233.137:19468"
    6) ""
3) 1) (integer) 14
    2) (integer) 1639992068
    3) (integer) 13279
    4) 1) "GET"
       2) "key:__rand_int__"
    5) "167.220.233.137:46504"
    6) ""
4) 1) (integer) 13
    2) (integer) 1639990412
    3) (integer) 14152
    4) 1) "GET"
       2) "key:__rand_int__"
    5) "167.220.233.137:39900"
    6) ""
5) 1) (integer) 12
    2) (integer) 1639990251
    3) (integer) 10710
    4) 1) "GET"
       2) "key:__rand_int__"
    5) "167.220.233.137:52381"
    6) ""
6) 1) (integer) 11
    2) (integer) 1639989209
    3) (integer) 11665
    4) 1) "GET"
       2) "key:__rand_int__"
    5) "167.220.233.137:38779"
    6) ""
7) 1) (integer) 10
    2) (integer) 1639989142
    3) (integer) 13642
    4) 1) "GET"
       2) "key:__rand_int__"
    5) "167.220.233.137:12348"
    6) ""
8) 1) (integer) 9
    2) (integer) 1639988822
    3) (integer) 22073
    4) 1) "GET"
       2) "key:__rand_int__"
    5) "167.220.233.137:51454"
    6) ""
9) 1) (integer) 8
    2) (integer) 1639988414
    3) (integer) 13668
    4) 1) "GET"
       2) "key:__rand_int__"
    5) "167.220.233.137:1550"
    6) ""
10) 1) (integer) 7
    2) (integer) 1639987239
    3) (integer) 18846
    4) 1) "GET"
       2) "key:__rand_int__"
    5) "167.220.233.137:57350"
    6) ""
11) 1) (integer) 6
    2) (integer) 1639986196
    3) (integer) 12921
    4) 1) "GET"
       2) "key:__rand_int__"
    5) "167.220.233.137:1739"
    6) ""
12) 1) (integer) 5
    2) (integer) 1639986196
    3) (integer) 15833
    4) 1) "GET"
       2) "key:__rand_int__"
    5) "167.220.233.137:1739"
    6) ""
13) 1) (integer) 4
    2) (integer) 1639985175
    3) (integer) 14434
    4) 1) "GET"
       2) "key:__rand_int__"
    5) "167.220.233.137:1649"
    6) ""
14) 1) (integer) 3
    2) (integer) 1639984227
    3) (integer) 61332
    4) 1) "GET"
       2) "key:__rand_int__"
    5) "167.220.233.137:24878"
    6) ""
15) 1) (integer) 2
    2) (integer) 1639984227
    3) (integer) 27560
    4) 1) "GET"
       2) "key:__rand_int__"
    5) "167.220.233.137:7637"
    6) ""
16) 1) (integer) 1
    2) (integer) 1639983695
    3) (integer) 10361
    4) 1) "SET"
       2) "Message_dd2_0"
       3) "eyJ0eXAiOiJKV1QiLCJub25jZSI6Inp1d2hMNzhSWDJsdGZITlN1TDYyOEhpRDNrTzhWSnJXZl9CNEtVcjBFTWsiLCJhbGciOiJSUzI1NiIsIng1dCI6IkpSNGxDdzkw... (4140520 more bytes)"
    5) "167.220.233.137:1166"
    6) "MININT-S4MGVOU"
17) 1) (integer) 0
    2) (integer) 1639983310
    3) (integer) 16577
    4) 1) "SET"
       2) "Message_dd_2222"
       3) "eyJ0eXAiOiJKV1QiLCJub25jZSI6Inp1d2hMNzhSWDJsdGZITlN1TDYyOEhpRDNrTzhWSnJXZl9CNEtVcjBFTWsiLCJhbGciOiJSUzI1NiIsIng1dCI6IkpSNGxDdzkw... (7774 more bytes)"
    5) "167.220.233.137:58313"
    6) "MININT-S4MGVOU"
>slowlog len
(integer) 17
>slowlog reset
OK
>slowlog len
(integer) 0

 

Each entry from the slow log is comprised of the following six values:

  1. A unique progressive identifier for every slow log entry.
  2. The unix timestamp at which the logged command was processed.
  3. The amount of time needed for its execution, in microseconds.
  4. The array composing the arguments of the command.
  5. Client IP address and port.
  6. Client name if set via the CLIENT SETNAME command.

 

参考资料

SLOWLOG GET [count]https://redis.io/commands/slowlog-get

管理 Azure Cache for Redis 的服务器负载: https://docs.azure.cn/zh-cn/azure-cache-for-redis/cache-best-practices-server-load#value-sizes

相关文章
|
5月前
|
缓存 NoSQL 关系型数据库
美团面试:MySQL有1000w数据,redis只存20w的数据,如何做 缓存 设计?
美团面试:MySQL有1000w数据,redis只存20w的数据,如何做 缓存 设计?
美团面试:MySQL有1000w数据,redis只存20w的数据,如何做 缓存 设计?
|
16天前
|
存储 缓存 NoSQL
Redis专题-实战篇二-商户查询缓存
本文介绍了缓存的基本概念、应用场景及实现方式,涵盖Redis缓存设计、缓存更新策略、缓存穿透问题及其解决方案。重点讲解了缓存空对象与布隆过滤器的使用,并通过代码示例演示了商铺查询的缓存优化实践。
100 1
Redis专题-实战篇二-商户查询缓存
|
5月前
|
缓存 NoSQL Java
Redis+Caffeine构建高性能二级缓存
大家好,我是摘星。今天为大家带来的是Redis+Caffeine构建高性能二级缓存,废话不多说直接开始~
726 0
|
2月前
|
缓存 监控 Linux
Linux系统清理缓存(buff/cache)的有效方法。
总结而言,在大多数情形下你不必担心Linux中buffer与cache占用过多内存在影响到其他程序运行;因为当程序请求更多内存在没有足够可用资源时,Linux会自行调整其占有量。只有当你明确知道当前环境与需求并希望立即回收这部分资源给即将运行重负载任务之前才考虑上述方法去主动干预。
752 10
|
16天前
|
缓存 NoSQL 关系型数据库
Redis缓存和分布式锁
Redis 是一种高性能的键值存储系统,广泛用于缓存、消息队列和内存数据库。其典型应用包括缓解关系型数据库压力,通过缓存热点数据提高查询效率,支持高并发访问。此外,Redis 还可用于实现分布式锁,解决分布式系统中的资源竞争问题。文章还探讨了缓存的更新策略、缓存穿透与雪崩的解决方案,以及 Redlock 算法等关键技术。
|
3月前
|
存储 缓存 NoSQL
Spring Cache缓存框架
Spring Cache是Spring体系下的标准化缓存框架,支持多种缓存(如Redis、EhCache、Caffeine),可独立或组合使用。其优势包括平滑迁移、注解与编程两种使用方式,以及高度解耦和灵活管理。通过动态代理实现缓存操作,适用于不同业务场景。
316 0
|
5月前
|
消息中间件 缓存 NoSQL
基于Spring Data Redis与RabbitMQ实现字符串缓存和计数功能(数据同步)
总的来说,借助Spring Data Redis和RabbitMQ,我们可以轻松实现字符串缓存和计数的功能。而关键的部分不过是一些"厨房的套路",一旦你掌握了这些套路,那么你就像厨师一样可以准备出一道道饕餮美食了。通过这种方式促进数据处理效率无疑将大大提高我们的生产力。
191 32
|
5月前
|
缓存 NoSQL Java
Redis:现代服务端开发的缓存基石与电商实践-优雅草卓伊凡
Redis:现代服务端开发的缓存基石与电商实践-优雅草卓伊凡
109 5
Redis:现代服务端开发的缓存基石与电商实践-优雅草卓伊凡
|
7月前
|
缓存 NoSQL Java
Redis应用—8.相关的缓存框架
本文介绍了Ehcache和Guava Cache两个缓存框架及其使用方法,以及如何自定义缓存。主要内容包括:Ehcache缓存框架、Guava Cache缓存框架、自定义缓存。总结:Ehcache适合用作本地缓存或与Redis结合使用,Guava Cache则提供了更灵活的缓存管理和更高的并发性能。自定义缓存可以根据具体需求选择不同的数据结构和引用类型来实现特定的缓存策略。
398 16
Redis应用—8.相关的缓存框架
|
7月前
|
缓存 监控 NoSQL
Redis--缓存击穿、缓存穿透、缓存雪崩
缓存击穿、缓存穿透和缓存雪崩是Redis使用过程中可能遇到的常见问题。理解这些问题的成因并采取相应的解决措施,可以有效提升系统的稳定性和性能。在实际应用中,应根据具体场景,选择合适的解决方案,并持续监控和优化缓存策略,以应对不断变化的业务需求。
1298 29

热门文章

最新文章