首页 > 解决方案 > 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)

如果服务器没有正确响应,我希望看到一些异常,但绝对没有。我们唯一能看到的是超慢的响应。

标签: springspring-bootredisjedis

解决方案


我们发现这实际上是由 Jedis 实现的一个已知问题引起的:

https://jira.spring.io/projects/DATAREDIS/issues/DATAREDIS-678?filter=allopenissues


推荐阅读