我使用前端Spring Cloud应用程序(微服务)作为Zuul代理(@EnableZuulProxy
),将请求从外部源路由到使用Spring Cloud编写的其他内部微服务(Spring引导)
Zuul服务器直接来自示例部分中的应用程序
@SpringBootApplication
@Controller
@EnableZuulProxy
@EnableDiscoveryClient
public class ZuulServerApplication {
public static void main(String[] args) {
new SpringApplicationBuilder(ZuulServerApplication.class).web(true).run(args);
}
}
我在本地运行了这组服务,看起来一切都很好,但如果我在有一定负载的网络上或通过VPN运行它,我就会开始看到Zuul转发错误,我在日志中看到的是客户端超时。
有没有办法改变祖尔前锋的暂停时间,这样我就可以把这个问题从我的当务之急中消除?有哪些可访问的参数设置?
在我的情况下,我不得不更改以下属性:
zuul.host.socket-timeout-millis=30000
要设置的属性为:一般情况下为ribbon.ReadTimeout
,特定服务为<service>.ribbon.ReadTimeout
,单位为毫秒。Ribbon wiki有一些示例。这个javadoc具有属性名称。
我也遇到过同样的问题:在长请求中,尽管设置了ribbon.ReadTimeout=10000
,但Zuul的hystrix命令在大约一秒钟后仍会超时。
我通过完全禁用超时来解决这个问题:
hystrix:
command:
default:
execution:
timeout:
enabled: false
另一种可行的方法是将Zuul的Hystrix隔离策略更改为THREAD:
hystrix:
command:
default:
execution:
isolation:
strategy: THREAD
thread:
timeoutInMilliseconds: 10000
这对我有效,我必须在application.yml
:中设置连接和套接字超时
zuul:
host:
connect-timeout-millis: 60000 # starting the connection
socket-timeout-millis: 60000 # monitor the continuous incoming data flow
我不得不更改两个超时,以迫使zuul停止超时长时间运行的请求。即使hystrix超时被禁用,功能区仍然会超时。
hystrix:
command:
default:
execution:
timeout:
enabled: false
ribbon:
ReadTimeout: 100000
ConnectTimeout: 100000
如果Zuul使用服务发现,则需要使用ribbon.ReadTimeout
和ribbon.SocketTimeout
功能区属性配置这些超时。
如果您通过指定URL配置了Zuul路由,则需要使用zuul.host.connect-timeout-millis
和zuul.host.socket-timeout-millis
我指的是
zuul:
routes:
dummy-service:
path: /dummy/**
我遇到了类似的问题,我试图全局设置超时,同时设置Hystrix和Ribbon超时的顺序也很重要。
在花了大量时间之后,我最终得到了这个解决方案。由于数据量巨大,我的服务耗时50秒。
在更改Timeout:的默认值之前需要考虑的要点
Hystrix时间应大于RibbonReadTimeout和ConnectionTimeout的组合时间。
仅对特定服务使用,这意味着不要全局设置(这不起作用)。
我的意思是使用这个:
command:
your-service-name:
而不是这个:
command:
default:
工作解决方案:
hystrix:
command:
your-service-name:
execution:
isolation:
strategy: THREAD
thread:
timeoutInMilliseconds: 95000
your-service-name:
ribbon:
ConnectTimeout: 30000
ReadTimeout: 60000
MaxTotalHttpConnections: 500
MaxConnectionsPerHost: 100
参考
只有application.yml
上的这些设置对我有效:
ribbon:
ReadTimeout: 90000
ConnectTimeout: 90000
eureka:
enabled: true
zuul:
host:
max-total-connections: 1000
max-per-route-connections: 100
semaphore:
max-semaphores: 500
hystrix:
command:
default:
execution:
isolation:
thread:
timeoutInMilliseconds: 1000000
希望它能帮助到别人!