【发布时间】:2020-01-10 03:18:04
【问题描述】:
我们在带有 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)
如果服务器没有正确响应,我希望看到一些异常,但绝对没有。我们只能看到超慢的响应。
【问题讨论】:
-
你试过 Redisson java 客户端吗?它没有这样的问题
标签: spring spring-boot redis jedis