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

本文涉及的产品
云数据库 Redis 版,标准版 2GB
推荐场景:
搭建游戏排行榜
云原生内存数据库 Tair,内存型 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

相关实践学习
基于Redis实现在线游戏积分排行榜
本场景将介绍如何基于Redis数据库实现在线游戏中的游戏玩家积分排行榜功能。
云数据库 Redis 版使用教程
云数据库Redis版是兼容Redis协议标准的、提供持久化的内存数据库服务,基于高可靠双机热备架构及可无缝扩展的集群架构,满足高读写性能场景及容量需弹性变配的业务需求。 产品详情:https://www.aliyun.com/product/kvstore     ------------------------------------------------------------------------- 阿里云数据库体验:数据库上云实战 开发者云会免费提供一台带自建MySQL的源数据库 ECS 实例和一台目标数据库 RDS实例。跟着指引,您可以一步步实现将ECS自建数据库迁移到目标数据库RDS。 点击下方链接,领取免费ECS&RDS资源,30分钟完成数据库上云实战!https://developer.aliyun.com/adc/scenario/51eefbd1894e42f6bb9acacadd3f9121?spm=a2c6h.13788135.J_3257954370.9.4ba85f24utseFl
相关文章
|
4天前
|
canal 缓存 NoSQL
Redis缓存与数据库如何保证一致性?同步删除+延时双删+异步监听+多重保障方案
根据对一致性的要求程度,提出多种解决方案:同步删除、同步删除+可靠消息、延时双删、异步监听+可靠消息、多重保障方案
Redis缓存与数据库如何保证一致性?同步删除+延时双删+异步监听+多重保障方案
|
5天前
|
存储 NoSQL Redis
SpringCloud基础7——Redis分布式缓存,RDB,AOF持久化+主从+哨兵+分片集群
Redis持久化、RDB和AOF方案、Redis主从集群、哨兵、分片集群、散列插槽、自动手动故障转移
SpringCloud基础7——Redis分布式缓存,RDB,AOF持久化+主从+哨兵+分片集群
|
15天前
|
缓存 NoSQL 关系型数据库
MySQL与Redis缓存一致性的实现与挑战
在现代软件开发中,MySQL作为关系型数据库管理系统,广泛应用于数据存储;而Redis则以其高性能的内存数据结构存储特性,常被用作缓存层来提升数据访问速度。然而,当MySQL与Redis结合使用时,确保两者之间的数据一致性成为了一个重要且复杂的挑战。本文将从技术角度分享MySQL与Redis缓存一致性的实现方法及其面临的挑战。
38 2
|
17天前
|
Java UED Maven
紧跟技术潮流:手把手教你构建响应式Vaadin应用,让用户体验无缝接轨!
【8月更文挑战第31天】本文从零开始,详细介绍如何使用强大的Java框架Vaadin构建流畅且响应式的Web应用程序。首先,确保安装JDK 1.8+、Maven 3.3.9+及IDE。接着,创建Maven项目并添加Vaadin依赖。然后,通过继承`UI`类创建主界面,并定义自定义主题与样式。利用Vaadin的响应式布局组件,如`HorizontalLayout`和`VerticalLayout`,实现多设备兼容性。
26 0
|
17天前
|
缓存 NoSQL Redis
Entity Framework Core 与 Redis 强强联手!实现高速缓存,提升应用性能超厉害
【8月更文挑战第31天】在现代应用开发中,结合 Entity Framework Core 与 Redis 可显著提升数据访问速度。Entity Framework Core 是一个强大的 ORM 框架,但处理频繁访问的数据时可能遇到性能瓶颈。Redis 作为高性能内存数据库,具备快速读写能力。两者结合利用 Redis 高速缓存,减少直接数据库访问,提高应用响应速度及性能。
25 0
|
24天前
|
缓存 NoSQL 网络安全
【Azure Redis 缓存】Azure Redis服务开启了SSL(6380端口), PHP如何访问缓存呢?
【Azure Redis 缓存】Azure Redis服务开启了SSL(6380端口), PHP如何访问缓存呢?
|
24天前
|
缓存 NoSQL Redis
【Azure Redis 缓存】Redission客户端连接Azure:客户端出现 Unable to send PING command over channel
【Azure Redis 缓存】Redission客户端连接Azure:客户端出现 Unable to send PING command over channel
|
24天前
|
存储 缓存 NoSQL
【Azure Redis 缓存】关于Azure Cache for Redis 服务在传输和存储键值对(Key/Value)的加密问题
【Azure Redis 缓存】关于Azure Cache for Redis 服务在传输和存储键值对(Key/Value)的加密问题
|
24天前
|
缓存 NoSQL Redis
【Azure Redis 缓存】Redis 连接失败
【Azure Redis 缓存】Redis 连接失败
|
24天前
|
缓存 NoSQL 网络协议
【Azure Redis 缓存】Lettuce 连接到Azure Redis服务,出现15分钟Timeout问题
【Azure Redis 缓存】Lettuce 连接到Azure Redis服务,出现15分钟Timeout问题
【Azure Redis 缓存】Lettuce 连接到Azure Redis服务,出现15分钟Timeout问题