【Azure Redis】Lettuce客户端遇见连接Azure Redis长达15分钟的超时

本文涉及的产品
云原生内存数据库 Tair,内存型 2GB
云数据库 Redis 版,标准版 2GB
推荐场景:
搭建游戏排行榜
简介: 【Azure Redis】Lettuce客户端遇见连接Azure Redis长达15分钟的超时

问题描述

在AKS环境中,应用使用Lettuce客户端连接Azure Redis,遇见了长达15分钟的超时情况

 

问题解答

在AKS中的节点操作系统,通常情况都是使用Linux,所以在连接Redis服务时候,TCP的连接需要基于系统级(Linux)的配置。 因为Azure Redis服务端对已经建立的连接最长空闲时间为10分钟,如果超时,Azure Redis会主动发起RST来断开TCP连接,而非正常的断开操作(四次挥手: FIN/ACK指令)。因此,因为服务器停止响应而未正常关闭连接时,Linux客户端 TCP 将继续重新传输数据包 15 分钟,然后才认为这个TCP连接死掉,直到这时,系统才会让Reids客户端重新建立新的连接。

 

Lettuce客户端 6.3.0 版本之前,并没有在底层适配TCP Keepalive 功能或是keepalive的发包间隔时间超过了10分钟,并且在Command Timeout 状态下无法直接放弃一个连接并马上重连,而是选择进入TCP重传状态等待连接恢复。

现在,Lettuce 已经在6.3.0版本中修复这个问题。通过配置TCP_USER_TIMEOUT来减少TCP重传的时间。

 

注:由于Azure Redis的升级机制或是其他意外问题(Failover),导致连接异常断开是预期的。所以必须要从Lettuce客户端入手,加强Lettuce的保活以及断开重连机制,从而将连接异常断开的影响降到最低。

 

附录一:关于Lettuce的Issue细节

请见:https://github.com/lettuce-io/lettuce-core/issues/2082#issuecomment-1702782618

 

@mp911de I verified 6.3.0.BUILD-SNAPSHOT and it succeeded. The details are as follows. I am not sure if we need to update a document to provide examples and reference it during official release. If necessary, please let me know where to add or modify it.

1. DO NOT configure TCP_USER_TIMEOUT will continue to be retransmitted.

2. Configure TCP_ USER_ TIMEOUT is 30 seconds, and a reconnection will be initiated using a new port 30 seconds after the first retransmission occurs!

 

my pom.xml is (notice: Linux need use native-epoll)

<dependency>
            <groupId>io.lettuce</groupId>
            <artifactId>lettuce-core</artifactId>
            <version>6.3.0.BUILD-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>io.netty</groupId>
            <artifactId>netty-transport-native-epoll</artifactId>
            <version>4.1.65.Final</version>
            <classifier>linux-x86_64</classifier>
        </dependency>

in debug, will see this log:

2023-09-01 21:30:20 [main] DEBUG i.l.core.resource.EpollProvider - Starting with epoll library
2023-09-01 21:30:20 [main] DEBUG i.l.c.r.DefaultEventLoopGroupProvider - Allocating executor io.netty.channel.e

参考资料

Linux 托管客户端应用程序的 TCP 设置: https://docs.azure.cn/zh-cn/azure-cache-for-redis/cache-best-practices-connection#tcp-settings-for-linux-hosted-client-applications

Lettuce TCP_USER_TIMEOUT : https://github.com/lettuce-io/lettuce-core/issues/2082#issuecomment-1702782618

 

相关实践学习
基于Redis实现在线游戏积分排行榜
本场景将介绍如何基于Redis数据库实现在线游戏中的游戏玩家积分排行榜功能。
云数据库 Redis 版使用教程
云数据库Redis版是兼容Redis协议标准的、提供持久化的内存数据库服务,基于高可靠双机热备架构及可无缝扩展的集群架构,满足高读写性能场景及容量需弹性变配的业务需求。 产品详情:https://www.aliyun.com/product/kvstore &nbsp; &nbsp; ------------------------------------------------------------------------- 阿里云数据库体验:数据库上云实战 开发者云会免费提供一台带自建MySQL的源数据库&nbsp;ECS 实例和一台目标数据库&nbsp;RDS实例。跟着指引,您可以一步步实现将ECS自建数据库迁移到目标数据库RDS。 点击下方链接,领取免费ECS&amp;RDS资源,30分钟完成数据库上云实战!https://developer.aliyun.com/adc/scenario/51eefbd1894e42f6bb9acacadd3f9121?spm=a2c6h.13788135.J_3257954370.9.4ba85f24utseFl
相关文章
|
20天前
|
NoSQL 网络协议 Redis
【Azure Redis】AKS中使用Lettuce连接Redis Cache出现 timed out 问题的解决思路
【Azure Redis】AKS中使用Lettuce连接Redis Cache出现 timed out 问题的解决思路
【Azure Redis】AKS中使用Lettuce连接Redis Cache出现 timed out 问题的解决思路
|
17天前
|
NoSQL 算法 Java
诡异!Redis Proxy RT上升后连接倾斜
本文细致地描述了关于Redis Proxy RT上升后连接倾斜问题的排查过程和根本原因,最后给出了优化方案。
|
20天前
|
存储 NoSQL Redis
【Azure Developer】一个复制Redis Key到另一个Redis服务的工具(redis_copy_net8)
【Azure Developer】一个复制Redis Key到另一个Redis服务的工具(redis_copy_net8)
【Azure Developer】一个复制Redis Key到另一个Redis服务的工具(redis_copy_net8)
|
20天前
|
NoSQL 网络协议 Linux
【AKS+Redis】AKS中客户端(ioredis)遇见Azure Redis服务Failover后链接中断的可能性
【AKS+Redis】AKS中客户端(ioredis)遇见Azure Redis服务Failover后链接中断的可能性
|
20天前
|
NoSQL Redis C++
【Azure Redis】对Azure Redis服务指标解释(Connections Created/Closed Per Second VS Connected Clinents)
【Azure Redis】对Azure Redis服务指标解释(Connections Created/Closed Per Second VS Connected Clinents)
|
21天前
|
缓存 监控 NoSQL
【Azure Redis 缓存】Azure Redis出现了超时问题后,记录一步一步的排查出异常的客户端连接和所执行命令的步骤
【Azure Redis 缓存】Azure Redis出现了超时问题后,记录一步一步的排查出异常的客户端连接和所执行命令的步骤
|
NoSQL Redis 数据库
一步一步学习Redis——连接服务的相关命令
一步一步学习Redis——连接服务的相关命令
一步一步学习Redis——连接服务的相关命令
|
NoSQL Java 编译器
一步一步学习Redis——Java连接Redis(Java中使用Redis命令)
一步一步学习Redis——Java连接Redis(Java中使用Redis命令)
一步一步学习Redis——Java连接Redis(Java中使用Redis命令)
|
NoSQL Redis
Redis 连接命令
Redis 命令用于在 redis 服务上执行操作。 要在 redis 服务上执行命令需要一个 redis 客户端。Redis 客户端在我们之前下载的的 redis 的安装包中。
1331 0