环境
openjdk:10.0.1-jre-slim
题
我有一个名为
serviceA
的功能区客户端和相关的serviceA.ribbon.ConnectTimeout=5000
serviceA.ribbon.ReadTimeout=15000
hystrix.command.serviceA.execution.isolation.thread.timeoutInMilliseconds = 20000
我还没有(有意地)在类路径上进行 spring-retry。我执行
./mvnw dependency:list | grep -i retry
并没有得到任何结果。在运行时,我收到这些警告:
The Hystrix timeout of 20000ms for the command serviceA is set lower than the combination of the Ribbon read and connect timeout, 40000ms.
我不确定这些数字来自哪里,因为我认为我将它们分别设置为 15 和 5 秒。为什么这个数字是两倍?
最佳答案
实际上,功能区超时包括所有相同的服务器重试和下一次服务器重试。
ribbonTimeout = (ribbon.ConnectTimeout + ribbon.ReadTimeout) * (ribbon.MaxAutoRetries + 1) * (ribbon.MaxAutoRetriesNextServer + 1);
// ...
if(hystrixTimeout < ribbonTimeout) {
LOGGER.warn("The Hystrix timeout of " + hystrixTimeout + "ms for the command " + commandKey +
" is set lower than the combination of the Ribbon read and connect timeout, " + ribbonTimeout + "ms.");
}
在您的配置中:
所以 hystrixTimeout 应该是:
(5000 + 15000) * (1 + 0) * (1 + 1) // -> 40000 ms
如果您选择不配置 Hystrix 超时,默认的 Hystrix 超时将为 40000 毫秒。
19.13 Zuul Timeouts in Spring Cloud Document
关于spring-cloud - Hystrix 和 Ribbon 超时警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50622668/