spring - Redis/Jedis 服务不正常
问题描述
我们在带有 Jedis 的 Spring Java 应用程序中使用 Redis 缓存,并且在高负载期间缓存卡住并且无法及时响应。
我们对 Jedis 连接进行了如下配置:
val clientConfiguration = JedisClientConfiguration
.builder()
.readTimeout(Duration.ofSeconds(2L))
.connectTimeout(Duration.ofSeconds(10L))
.usePooling()
.build()
val configuration = RedisStandaloneConfiguration(redisHost, Integer.parseInt(redisPort))
configuration.password = RedisPassword.of(redisPassword)
val jedisConnectionFactory = JedisConnectionFactory(configuration, clientConfiguration)
jedisConnectionFactory.poolConfig.apply {
maxTotal = 512
maxIdle = 256
minIdle = 16
maxWaitMillis = 2000L
blockWhenExhausted = true
}
Redis 服务器似乎没有负载,也没有显示任何错误。我们可以看到的唯一问题是使用时jstack
有数百个线程卡在RedisCache.get
:
java.lang.Thread.State: BLOCKED (on object monitor)
at org.springframework.data.redis.cache.RedisCache.get(RedisCache.java:117)
- waiting to lock <0x00000000c00bd5f8> (a org.springframework.data.redis.cache.RedisCache)
at org.springframework.cache.interceptor.CacheAspectSupport.execute(CacheAspectSupport.java:381)
at org.springframework.cache.interceptor.CacheAspectSupport.execute(CacheAspectSupport.java:345)
at org.springframework.cache.interceptor.CacheInterceptor.invoke(CacheInterceptor.java:61)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688)
如果服务器没有正确响应,我希望看到一些异常,但绝对没有。我们唯一能看到的是超慢的响应。
解决方案
我们发现这实际上是由 Jedis 实现的一个已知问题引起的:
https://jira.spring.io/projects/DATAREDIS/issues/DATAREDIS-678?filter=allopenissues
推荐阅读
- c# - 在 C# 中反序列化具有 CamelCase 和 snake_case 命名键的 JSON
- aws-lambda - 为什么在执行调用 cognito lambda 触发 PostConfirmation 和 PreTokenGeneration 的开玩笑测试时会出现随机错误?
- dart - 有没有办法从命令行应用程序注入键盘事件?
- javascript - 如何让我的 html 输入元素影响我的 javascript 类对象值(字符名称)
- python - 有没有一种简单有效的方法来使用 pygame 为平台游戏编写 python 中的跳跃和重力逻辑代码?
- c++ - 当我从文件中读取时,我得到了控制字符
- java - Derby 如何在现有列上添加 NOT NULL 约束
- selenium - 如何在python中总是将+1添加到0
- cuda - 使用 numba.cuda 在 GPU 上运行 Sympy lambdify 函数
- python - 如何克服python中的“classmethod不可调用”