当前位置: 首页 > news >正文

ribbon基于接口配置超时_feign的ribbon超时配置和hystrix的超时配置说明

先看下我的配置:

ribbon:

MaxAutoRetries: 1 #最大重试次数,当Eureka中可以找到服务,但是服务连不上时将会重试

MaxAutoRetriesNextServer: 1 #切换实例的重试次数

OkToRetryOnAllOperations: false # 对所有的操作请求都进行重试,如果是get则可以,如果是post,put等操作没有实现幂等的情况下是很危险的,所以设置为false

ConnectTimeout: 1000 #请求连接的超时时间

ReadTimeout: 1800 #请求处理的超时时间

hystrix:

command:

default:

execution:

isolation:

thread:

timeoutInMilliseconds: 3000

#如果配置ribbon的重试,hystrix的超时时间要大于ribbon的超时时间,ribbon才会重试

#hystrix的超时时间=(1 + MaxAutoRetries + MaxAutoRetriesNextServer) * ReadTimeout 比较好,具体看需求

Ribbon超时与Hystrix超时问题,为了确保Ribbon重试的时候不被熔断,我们就需要让Hystrix的超时时间大于Ribbon的超时时间,否则Hystrix命令超时后,该命令直接熔断,重试机制就没有任何意义了。

从上面的配置来说,ribbon超时配置为1800,请求超时后,该实例会重试1次,更新实例会重试1次。

所以hystrix的超时时间要大于 (1 + MaxAutoRetries + MaxAutoRetriesNextServer) * ReadTimeout 比较好,具体看需求进行配置。

Ribbon超时与Hystrix超时问题,为了确保Ribbon重试的时候不被熔断,我们就需要让Hystrix的超时时间大于Ribbon的超时时间,否则Hystrix命令超时后,该命令直接熔断,重试机制就没有任何意义了。

补充知识:Spring Cloud Feign 第一次调用超时(Read timed out)的解决办法

feign-client在第一次调用微服务会出现Read timed out异常,提示的报错信息:

java.net.SocketTimeoutException: Read timed out

这是由于在调用其他微服务接口前,会去请求该微服务的相关信息(地址、端口等),并做一些初始化操作,由于默认的懒加载特性,导致了在第一次调用时,出现超时的情况,解决方法主要有两种:

第一种办法是设置超时时间,具体设置成多少,因项目而异,配置如下:

# 全局关闭Hystrix超时,对所有微服务有效

hystrix.command.default.execution.timeout.enabled: false

# 关闭某一个微服务的超时

hystrix.command..execution.timeout.enabled: false

# 全局设置超时时间为60秒

hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds: 60000

# 设置某一个微服务的超时时间为60秒

hystrix.command..execution.isolation.thread.timeoutInMilliseconds: 60000

# 设置ribbon超时时间

ribbon:

ReadTimeout: 20000

ConnectTimeout: 20000

第二种办法,也是比较推荐的方式,配置ribbon立即加载,此处需要注意的是,光配置立即加载是不生效的,还要配置客户端列表,配置如下,详细配置请点击:

ribbon:

eager-load:

enabled: true

clients: distribution, material-product, outer-data

最后附上未开启立即加载时,第一次调用打印的日志:

2019-05-27 18:05:33.819|INFO|1986|http-nio-18884-exec-2|clipcloud-configuration|3752c9412075144e|3752c9412075144e|false|com.migu.clipcloud.configuration.ConfigurationServiceApplication.test1-55|time:2019-05-27 18:05:33.819

2019-05-27 18:05:33.826|INFO|1986|hystrix-distribution-1|clipcloud-configuration|3752c9412075144e|405382c2fc629614|false|com.migu.clipcloud.services.client.FeignHeadConfiguration.lambda$requestInterceptor$2-51|add request header for feignclient, key:cookie,value:JSESSIONID.8250e395=node08z98wvylx12lwh89c6v09qk92.node0; screenResolution=1440x900; m=2258:cmFiYml0bXE6cmFiYml0bXE%253D

2019-05-27 18:05:33.828|INFO|1986|hystrix-distribution-1|clipcloud-configuration|3752c9412075144e|405382c2fc629614|false|org.springframework.context.support.AbstractApplicationContext.prepareRefresh-588|Refreshing SpringClientFactory-distribution: startup date [Mon May 27 18:05:33 CST 2019]; parent: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@203dd56b

2019-05-27 18:05:33.850|INFO|1986|hystrix-distribution-1|clipcloud-configuration|3752c9412075144e|405382c2fc629614|false|org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.-153|JSR-330 'javax.inject.Inject' annotation found and supported for autowiring

2019-05-27 18:05:33.864|INFO|1986|hystrix-distribution-1|clipcloud-configuration|3752c9412075144e|405382c2fc629614|false|com.netflix.config.ChainedDynamicProperty$ChainLink.checkAndFlip-115|Flipping property: distribution.ribbon.ActiveConnectionsLimit to use NEXT property: niws.loadbalancer.availabilityFilteringRule.activeConnectionsLimit = 2147483647

2019-05-27 18:05:33.865|INFO|1986|hystrix-distribution-1|clipcloud-configuration|3752c9412075144e|405382c2fc629614|false|com.netflix.util.concurrent.ShutdownEnabledTimer.-58|Shutdown hook installed for: NFLoadBalancer-PingTimer-distribution

2019-05-27 18:05:33.866|INFO|1986|hystrix-distribution-1|clipcloud-configuration|3752c9412075144e|405382c2fc629614|false|com.netflix.loadbalancer.BaseLoadBalancer.initWithConfig-192|Client: distribution instantiated a LoadBalancer: DynamicServerListLoadBalancer:{NFLoadBalancer:name=distribution,current list of Servers=[],Load balancer stats=Zone stats: {},Server stats: []}ServerList:null

2019-05-27 18:05:33.884|INFO|1986|hystrix-distribution-1|clipcloud-configuration|3752c9412075144e|405382c2fc629614|false|com.netflix.loadbalancer.DynamicServerListLoadBalancer.enableAndInitLearnNewServersFeature-222|Using serverListUpdater PollingServerListUpdater

2019-05-27 18:05:33.886|INFO|1986|hystrix-distribution-1|clipcloud-configuration|3752c9412075144e|405382c2fc629614|false|com.netflix.config.ChainedDynamicProperty$ChainLink.checkAndFlip-115|Flipping property: distribution.ribbon.ActiveConnectionsLimit to use NEXT property: niws.loadbalancer.availabilityFilteringRule.activeConnectionsLimit = 2147483647

2019-05-27 18:05:33.887|INFO|1986|hystrix-distribution-1|clipcloud-configuration|3752c9412075144e|405382c2fc629614|false|com.netflix.loadbalancer.DynamicServerListLoadBalancer.restOfInit-150|DynamicServerListLoadBalancer for client distribution initialized: DynamicServerListLoadBalancer:{NFLoadBalancer:name=distribution,current list of Servers=[192.168.26.103:18887],Load balancer stats=Zone stats: {defaultzone=[Zone:defaultzone; Instance count:1; Active connections count: 0; Circuit breaker tripped count: 0; Active connections per server: 0.0;]

},Server stats: [[Server:192.168.26.103:18887; Zone:defaultZone; Total Requests:0; Successive connection failure:0; Total blackout seconds:0; Last connection made:Thu Jan 01 08:00:00 CST 1970; First connection made: Thu Jan 01 08:00:00 CST 1970; Active Connections:0; total failure count in last (1000) msecs:0; average resp time:0.0; 90 percentile resp time:0.0; 95 percentile resp time:0.0; min resp time:0.0; max resp time:0.0; stddev resp time:0.0]

]}ServerList:org.springframework.cloud.netflix.ribbon.eureka.DomainExtractingServerList@173441c2

2019-05-27 18:05:33.906|INFO|1986|http-nio-18884-exec-2|clipcloud-configuration|3752c9412075144e|3752c9412075144e|false|com.migu.clipcloud.configuration.ConfigurationServiceApplication.test1-57|time:2019-05-27 18:05:33.906

2019-05-27 18:05:34.888|INFO|1986|PollingServerListUpdater-0|clipcloud-configuration||||com.netflix.config.ChainedDynamicProperty$ChainLink.checkAndFlip-115|Flipping property: distribution.ribbon.ActiveConnectionsLimit to use NEXT property: niws.loadbalancer.availabilityFilteringRule.activeConnectionsLimit = 2147483647

以上这篇feign的ribbon超时配置和hystrix的超时配置说明就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持龙方网络。

相关文章:

  • 怎么把好几行弄成一行_怎么在word文档里把很多行一下合并成一行
  • controller不跳转页面的几个原因_为什么很多人30岁了,还不结婚,有这几个原因...
  • clob存base64文件存不进去_cephfs:文件的扩展属性xattr
  • 山地车中轴进水表现_求山地自行车各部位上油的方法。特别是中轴和花鼓
  • matlab建立ar时间序列模型_请教matlab下建立AR模型的问题(附代码)
  • jpg图片使用pil的resize后_Python Pillow 和 cv2 图片 resize 速度的比较
  • 小白学vb还是python_小白学 Python(6):基础运算符(下)
  • qt 表格中插入一行_表格中插入列,如何不影响其他表格,1.3%的人还不会?
  • # 睡眠3秒_床上这样睡觉的人,睡眠质量多半不好
  • l4168升级固件出错如何恢复_苹果 iOS 13 / iPadOS 官方测试版固件 IPSW 下载升级降级与恢复教程...
  • 时序约束优先级_如何写出时序收敛的代码
  • 移动端布局三种视口_移动端布局适配
  • 柱形图无数据可选中_让领导看呆!Excel多层柱形图来了
  • ios 监听一个控制器的属性_iOS控制器间跳转
  • 语言中日期间的天数怎么计算_计算员工工龄,这个问题千万要注意
  • 10个最佳ES6特性 ES7与ES8的特性
  • Angular6错误 Service: No provider for Renderer2
  • canvas 五子棋游戏
  • emacs初体验
  • Vue全家桶实现一个Web App
  • 动手做个聊天室,前端工程师百无聊赖的人生
  • 爬虫进阶 -- 神级程序员:让你的爬虫就像人类的用户行为!
  • 容器化应用: 在阿里云搭建多节点 Openshift 集群
  • 使用common-codec进行md5加密
  • 新书推荐|Windows黑客编程技术详解
  • 一加3T解锁OEM、刷入TWRP、第三方ROM以及ROOT
  • 异步
  • 阿里云API、SDK和CLI应用实践方案
  • 继 XDL 之后,阿里妈妈开源大规模分布式图表征学习框架 Euler ...
  • 容器镜像
  • # Swust 12th acm 邀请赛# [ E ] 01 String [题解]
  • #、%和$符号在OGNL表达式中经常出现
  • (1) caustics\
  • (10)ATF MMU转换表
  • (3)llvm ir转换过程
  • (安全基本功)磁盘MBR,分区表,活动分区,引导扇区。。。详解与区别
  • (二)Linux——Linux常用指令
  • (每日持续更新)jdk api之StringBufferInputStream基础、应用、实战
  • (入门自用)--C++--抽象类--多态原理--虚表--1020
  • (深度全面解析)ChatGPT的重大更新给创业者带来了哪些红利机会
  • (一)Thymeleaf用法——Thymeleaf简介
  • .360、.halo勒索病毒的最新威胁:如何恢复您的数据?
  • .bat批处理(三):变量声明、设置、拼接、截取
  • .bat文件调用java类的main方法
  • .NET CF命令行调试器MDbg入门(三) 进程控制
  • .NET Core6.0 MVC+layui+SqlSugar 简单增删改查
  • .net core控制台应用程序初识
  • .NET/ASP.NETMVC 大型站点架构设计—迁移Model元数据设置项(自定义元数据提供程序)...
  • /ThinkPHP/Library/Think/Storage/Driver/File.class.php  LINE: 48
  • :如何用SQL脚本保存存储过程返回的结果集
  • @四年级家长,这条香港优才计划+华侨生联考捷径,一定要看!
  • [ 渗透工具篇 ] 一篇文章让你掌握神奇的shuize -- 信息收集自动化工具
  • [20170705]lsnrctl status LISTENER_SCAN1
  • [ai笔记3] ai春晚观后感-谈谈ai与艺术
  • [BUAA软工]第一次博客作业---阅读《构建之法》