原有代码用的eureka,服务上线和下线速度慢,有时候服务kill-9 在列表中好久不下线。踢出无效服务的时间也没找到参数调整时间间隔。
于是转为nacos,发现上下线也是有延迟的,而且服务下线时api调用存在异常(实际访问的下线的服务肯定是异常了),但是看到有的说nacos秒级上下线服务,所以还是可以配置的吧。
于是找到了这些参数
hystrix.command.default.execution.timeout.enabled=true
# 熔断的超时时间
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=25000
# 是否所有操作都进行重试
ribbon.OkToRetryOnAllOperations=true
# 读超时时间
ribbon.ReadTimeout=20000
# Connection建立的超时时间
ribbon.ConnectTimeout=1000
# 同一实例最大重试次数,不包括首次调用
ribbon.MaxAutoRetries=1
# 重试其他实例的最大重试次数,不包括首次所选的server
ribbon.MaxAutoRetriesNextServer=1
# 在网关中配置一个较小的值,让网关能够比较及时的获得最新服务列表
ribbon.ServerListRefreshInterval=1
spring.cloud.gateway.discovery.locator.enabled=true
spring.cloud.loadbalancer.retry.enabled=false
ribbon.eager-load.enabled=true
ribbon.ServerListRefreshInterval=1
ConnectTimeout设置的小一些,服务下线过程中,访问失败,可以快速重试。
重试需要pom中加入依赖
<dependency>
<groupId>org.springframework.retry</groupId>
<artifactId>spring-retry</artifactId>
</dependency>
关于ServerListRefreshInterval
参阅 https://blog.csdn.net/weixin_34019929/article/details/89046352
关于重试参阅重试机制配置 https://blog.csdn.net/qq_32486913/article/details/80622847