redis.clients.jedis.exceptions.JedisClusterMaxRedirectionsException: Too many Cluster redirections?
由于redis是单线程处理请求的,如果一条命令执行特别缓慢,那么新到来的请求就会放入tcp队列等待执行,如果待处理的命令堆积的数量超过了tcp队列容忍的长度, 那么就会拒绝该请求。
异常的堆栈信息描述的过程如下
redis.clients.jedis.exceptions.JedisClusterMaxRedirectionsException: Too many Cluster redirections?
at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:97)
at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:152)
at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:131)
at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:152)
at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:131)
at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:152)
at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:131)
at redis.clients.jedis.JedisClusterCommand.run(JedisClusterCommand.java:30)
at redis.clients.jedis.JedisCluster.get(JedisCluster.java:81)
1、jedis-client 先通过key计算slot, 然后根据slot查询slot到服务器的映射表,假设这个key由server1负责, 那么直接向server1发送请求
2、server1由于执行慢的命令,且tcp队列满了,那么直接拒绝jedis-client
3、jedis-client被拒绝之后,怀疑server1 不可用,然后随机请求一个新的服务器server2
4、server2 告诉jedis-client 还是由server1负责这个key对应的slot,
5、jedis-client再次向server1发起请求,
6、server1由于执行慢的命令,且tcp队列任然满,那么还是直接拒绝jedis-client
当请求的次数超过5次,抛出JedisClusterMaxRedirectionsException异常
解决方案
1、通过观察slow log 优化慢的命令 参考Redis Slowlog启用
2、redis 集群扩容,这样能减少redis每个进程需要处理的命令总量,同时也间接地增加了tcp队列的长度
如果觉得对你有帮助,请杯啤酒分享你快乐把!,谢谢
Posted in: redis
Comments are closed.