无法为功能区和 hystrix 设置超时
Posted
技术标签:
【中文标题】无法为功能区和 hystrix 设置超时【英文标题】:Not able to set timeout for ribbon and hyxtrix 【发布时间】:2019-01-27 22:20:05 【问题描述】:我正在尝试在 application.yml 中设置属性以设置功能区和 hystrix 的超时,但我无法做到这一点。我总是遇到同样的问题: “未知属性 hystrix.command” 和 “未知属性ribbon.ConnectTimeout”
hystrix:
command:
default:
execution:
isolation:
thread:
timeoutInMilliseconds: 11000
ribbon:
ConnectTimeout: 10000
ReadTimeout: 10000
使用 Finchley.SR1 顺便说一句。
总是遇到同样的错误:
2018-08-21 19:18:31.695 WARN 13534 --- [io-8765-exec-10] o.s.c.n.z.f.r.s.AbstractRibbonCommand : The Hystrix timeout of 3000ms for the command flight-service is set lower than the combination of the Ribbon read and connect timeout, 4000ms.
2018-08-21 19:18:32.752 WARN 13534 --- [io-8765-exec-10] o.s.c.n.z.filters.post.SendErrorFilter : Error during filtering
com.netflix.zuul.exception.ZuulException:
at org.springframework.cloud.netflix.zuul.filters.post.SendErrorFilter.findZuulException(SendErrorFilter.java:114) ~[spring-cloud-netflix-zuul-2.0.1.RELEASE.jar:2.0.1.RELEASE]
at org.springframework.cloud.netflix.zuul.filters.post.SendErrorFilter.run(SendErrorFilter.java:76) ~[spring-cloud-netflix-zuul-2.0.1.RELEASE.jar:2.0.1.RELEASE]
at com.netflix.zuul.ZuulFilter.runFilter(ZuulFilter.java:117) [zuul-core-1.3.1.jar:1.3.1]
at com.netflix.zuul.FilterProcessor.processZuulFilter(FilterProcessor.java:193) [zuul-core-1.3.1.jar:1.3.1]
at com.netflix.zuul.FilterProcessor.runFilters(FilterProcessor.java:157) [zuul-core-1.3.1.jar:1.3.1]
at com.netflix.zuul.FilterProcessor.error(FilterProcessor.java:105) [zuul-core-1.3.1.jar:1.3.1]
at com.netflix.zuul.ZuulRunner.error(ZuulRunner.java:112) [zuul-core-1.3.1.jar:1.3.1]
【问题讨论】:
请查看此链接 ***.com/a/44918316/9183844 【参考方案1】:我去 Finchley 后遇到了同样的错误。调整ribbon.ConnectTimeout和ribbon.ReadTimeout后,错误消失了。
ribbon:
ConnectTimeout: 2000
ReadTimeout: 2000
尝试运行负载测试(例如在 jMeter 中),看看负载下服务器的最大响应时间是多少,可能读取 10000 毫秒,连接 10000 毫秒是不够的。
附言
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds 必须大于ribbon.ConnectTimeout + ribbon.ReadTimeout。
【讨论】:
【参考方案2】:虽然它说未知属性,但在 zuul 网关中添加属性可以正常工作以调整超时。下面是我可以让它工作的配置。
hystrix.command.default.execution.timeout.enabled= true
ribbon.ReadTimeout=5000
ribbon.ConnectTimeout=5000
#(ribbon.ReadTimeout + ribbon.connectTimeout) * (1+ribbon.maxAutoRetries(default 0) * (ribbon.MaxAutoRetriesNextServer (default 1) + 1)
#timeoutInMilliseconds= (5000 + 5000) * (1+0)*(1+1) =20000
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=21000
【讨论】:
以上是关于无法为功能区和 hystrix 设置超时的主要内容,如果未能解决你的问题,请参考以下文章
带有 feign 和 hystrix 的 Spring Boot:无法让请求超时工作