我们项目是三主三从部署在线上环境,项目中使用redisson去读取redis集群的KV,有时候发现会报下面这个错误:
经过一些网站的搜索和配置文件的了解,最后在redisson的FAQ找到如下解决方案,用下面这个解决方案,通过线上观察,基本解决:
Q: I saw a RedisTimeOutException, What does it mean? What shall I do? Can Redisson Team fix it?
A :
There are three main reasons:
- All netty threads are busy, leading to delays in both Redis response decoding and sending commands to Redis
- All connections are busy
- Redis server takes too long to respond the request.
First try to set follow values for nettyThreads
setting: 32, 64, 128, 256 this allow Redisson to get free netty thread to decode response or send command. Next, try to increase connection pool
setting so that Redisson can stand a better chance in getting a free connection. Also, it is recommended to adjust the retryAttempts
and retryInterval
to a reasonable value so that a command can still gracefully fail without having the end user wait forever.
Complex commands such as keys
, hmget
and big loops in Lua scripts are more likely to see it than other commands. It is important to understand an operation can still timeout despite the absence of it from the Redis slowlog. Slowlogs only record the time a command is been processed by the Redis event loop and not anything before or after. Network issue may also cause this exception when a response is still in-flight.
2019-08-08添加
如果还报错,请按照下面的配置添加
"connectTimeout" : 10000, "timeout" : 3000, "retryInterval" : 1500, "retryAttempts": 3, "masterConnectionMinimumIdleSize" : 64, "masterConnectionPoolSize": 64, "slaveConnectionMinimumIdleSize" : 64, "slaveConnectionPoolSize": 64
参考网站: