关键词:
参数配置
参数说明 | 值 | 备注 |
---|---|---|
groupKey | productStockOpLog | group标识,一个group使用一个线程池 |
commandKey | addProductStockOpLog | command标识 |
fallbackMethod | addProductStockOpLogFallback | fallback方法,两者需要返回值和参数相同 |
超时时间设置 | 400ms | 执行策略,在THREAD模式下,达到超时时间,可以中断 For most circuits, you should try to set their timeout values close to the 99.5th percentile of a normal healthy system so they will cut off bad requests and not let them take up system resources or affect user behavior. |
统计窗口(10s)内最少请求数 | 10 | 熔断策略 |
熔断多少秒后去尝试请求 | 5s | 熔断策略,默认值 |
熔断阀值 | 10% | 熔断策略:一个统计窗口内有10%的请求处理失败,会触发熔断 |
线程池coreSize | 10 | 默认值(推荐值).在当前项目中,需要做依赖隔离的方法为发送一条MQ消息,发送MQ消息方法的TP99耗时在1ms以下,近2周单机QPS最高值在18左右,经过灰度验证了午高峰后(当日QPS>上周末QPS),ActiveThreads<=2,rejected=0,经过压测后得出结论:线程池大小为10足以应对2000QPS,前提发送MQ消息时耗时正常(该部分为实际项目中的情况,在此不做详述) |
线程池maxQueueSize | -1 | 即线程池队列为SynchronousQueue |
参数说明
其他参数可参见 https://github.com/Netflix/Hystrix/wiki/Con
分类 | 参数 | 作用 | 默认值 | 备注 |
---|---|---|---|---|
基本参数 | groupKey | 表示所属的group,一个group共用线程池 | getClass().getSimpleName(); | |
基本参数 | commandKey | 当前执行方法名 | ||
Execution ( 控制HystrixCommand.run()的执行策略) | execution.isolation.strategy | 隔离策略,有THREAD和SEMAPHORE THREAD | 以下几种可以使用SEMAPHORE模式: 只想控制并发度 外部的方法已经做了线程隔离 调用的是本地方法或者可靠度非常高、耗时特别小的方法(如medis) | |
Execution | execution.isolation.thread.timeoutInMilliseconds | 超时时间 | 1000ms | 默认值:1000 在THREAD模式下,达到超时时间,可以中断 在SEMAPHORE模式下,会等待执行完成后,再去判断是否超时 设置标准: 有retry,99meantime+avg meantime 没有retry,99.5meantime |
Execution | execution.timeout.enabled | 是否打开超时 | true | |
Execution | execution.isolation.thread.interruptOnTimeout | 是否打开超时线程中断 | true | THREAD模式有效 |
Execution | execution.isolation.semaphore.maxConcurrentRequests | 信号量最大并发度 | 10 | SEMAPHORE模式有效 |
Fallback ( 设置当fallback降级发生时的策略) | fallback.isolation.semaphore.maxConcurrentRequests | fallback最大并发度 | 10 | |
Fallback | fallback.enabled | fallback是否可用 | true | |
Circuit Breaker (配置熔断的策略) | circuitBreaker.enabled | 是否开启熔断 | true | |
Circuit Breaker | circuitBreaker.requestVolumeThreshold | 一个统计窗口内熔断触发的最小个数/10s | 20 | |
Circuit Breaker | circuitBreaker.sleepWindowInMilliseconds | 熔断多少秒后去尝试请求 | 5000ms | |
Circuit Breaker | circuitBreaker.errorThresholdPercentage | 失败率达到多少百分比后熔断 | 50 | 主要根据依赖重要性进行调整 |
Circuit Breaker | circuitBreaker.forceOpen | 是否强制开启熔断 | ||
Circuit Breaker | circuitBreaker.forceClosed | 是否强制关闭熔断 | 如果是强依赖,应该设置为true | |
Metrics (设置关于HystrixCommand执行需要的统计信息) | metrics.rollingStats.timeInMilliseconds | 设置统计滚动窗口的长度,以毫秒为单位。用于监控和熔断器。 | 10000 | 滚动窗口被分隔成桶(bucket),并且进行滚动。 例如这个属性设置10s(10000),一个桶是1s。 |
Metrics | metrics.rollingStats.numBuckets 设置统计窗口的桶数量 | 10 | metrics.rollingStats.timeInMilliseconds必须能被这个值整除 | |
Metrics | metrics.rollingPercentile.enabled | 设置执行时间是否被跟踪,并且计算各个百分比,50%,90%等的时间 | true | |
Metrics | metrics.rollingPercentile.timeInMilliseconds | 设置执行时间在滚动窗口中保留时间,用来计算百分比 | 60000ms | |
Metrics | metrics.rollingPercentile.numBuckets | 设置rollingPercentile窗口的桶数量 | 6 | metrics.rollingPercentile.timeInMilliseconds必须能被这个值整除 |
Metrics | metrics.rollingPercentile.bucketSize | 此属性设置每个桶保存的执行时间的最大值。 | 100 | 如果设置为100,但是有500次求情,则只会计算最近的100次 |
Metrics | metrics.healthSnapshot.intervalInMilliseconds | 采样时间间隔 | 500 | |
Request Context ( 设置HystrixCommand使用的HystrixRequestContext相关的属性) | requestCache.enabled | 设置是否缓存请求,request-scope内缓存 | true | |
Request Context | requestLog.enabled | 设置HystrixCommand执行和事件是否打印到HystrixRequestLog中 | ||
ThreadPool Properties(配置HystrixCommand使用的线程池的属性) | coreSize | 设置线程池的core size,这是最大的并发执行数量。 | 10 | 设置标准:coreSize = requests per second at peak when healthy × 99th percentile latency in seconds + some breathing room 大多数情况下默认的10个线程都是值得建议的 |
ThreadPool Properties | maxQueueSize | 最大队列长度。设置BlockingQueue的最大长度 | -1 | 默认值:-1 如果使用正数,队列将从SynchronousQueue改为LinkedBlockingQueue |
ThreadPool Properties | queueSizeRejectionThreshold | 设置拒绝请求的临界值 | 5 | 此属性不适用于maxQueueSize = - 1时 设置设个值的原因是maxQueueSize值运行时不能改变,我们可以通过修改这个变量动态修改允许排队的长度 |
ThreadPool Properties | keepAliveTimeMinutes | 设置keep-live时间 | 1分钟 | 这个一般用不到因为默认corePoolSize和maxPoolSize是一样的。 |
hystrix配置项说明
参考技术A###############Hystrix限流配置###############hystrix.command.default.execution.isolation.strategy=SEMAPHOREhystrix.command.default.execution.timeout.enabled=falsehystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=6000hystrix.command.default.execution.isolation.... 查看详情
Hystrix 配置说明:metrics.rollingStats.timeInMilliseconds
】Hystrix配置说明:metrics.rollingStats.timeInMilliseconds【英文标题】:HystrixConfigurationclarification:metrics.rollingStats.timeInMilliseconds【发布时间】:2019-01-0221:50:27【问题描述】:我正在尝试了解metrics.rollingStats.timeInMilliseconds和metrics.r 查看详情
hystrix参数配置(代码片段)
1、Hystrix参数配置文档 2、Hystrix参数配置示例importorg.springframework.beans.factory.annotation.Autowired;importorg.springframework.web.bind.annotation.GetMapping;importorg.springframework.web.bind.annotation.PathVariable;importorg.springframework.web.bind.annotation.RestControlle... 查看详情
springcloudspringbootmybatis分布式微服务云架构-hystrix参数详解(代码片段)
简介上节我们讨论了hystrix+feign+ribbon,但是可能很多人都知道hystrix还有线程隔离,信号量隔离,等等各种参数配置,在这几就记录下hystrix的参数,一、hystrix参数使用方法通过注解@HystrixCommand的commandProperties去配置,如下就... 查看详情
feignclient设置hystrix参数(代码片段)
序feign默认集成了hystrix,那么问题来了,如何像hystrixcommand那样设置每个方法的hystrix属性呢。实例@FeignClient("product")publicinterfaceRemoteProductService@RequestMapping(method=RequestMethod.GET,value="/product/productId")public 查看详情
springcloudspringbootmybatis分布式微服务云架构-hystrix参数详解(代码片段)
简介上节我们讨论了hystrix+feign+ribbon,但是可能很多人都知道hystrix还有线程隔离,信号量隔离,等等各种参数配置,在这几就记录下hystrix的参数,一、hystrix参数使用方法通过注解@HystrixCommand的commandProperties去配置,如下就是hystr... 查看详情
springcloud请求熔断服务降级hystrix-补充
Hystrix熔断的状态说明:如果服务没有问题即是"关闭"状态,阀值是指请求的次数,比如说阀值是100每10s有<100次的请求那么不会检测,如果请求次数>100那么会进行检测,如果成功比例<50%那么打开开关进入"打开"状态,当熔... 查看详情
springcloud-第六篇hystrix参数配置
1:概述Hystrix使用Archaius作为配置属性的默认实现。官方配置文档:https://github.com/Netflix/Hystrix/wiki/Configuration每个属性有四个优先级,依次增大:1:代码的全局默认值2:动态全局默认属性可以使用全局属性文件来更改全局默认值... 查看详情
javaspringboot微服务b2b2c电子商务系统-hystrix参数详解(代码片段)
简介上节我们讨论了hystrix+feign+ribbon,但是可能很多人都知道hystrix还有线程隔离,信号量隔离,等等各种参数配置,在这几就记录下hystrix的参数,一、hystrix参数使用方法通过注解@HystrixCommand的commandProperties去配置,如下就是hystr... 查看详情
方法参数不匹配的 Spring Hystrix 单一后备
】方法参数不匹配的SpringHystrix单一后备【英文标题】:SpringHystrixSingleFallbackwithMethodArgumentsNotMatching【发布时间】:2016-06-0515:40:52【问题描述】:我想知道是否可以实现以下类似的东西,因为我有很多端点变体,并且每个端点都... 查看详情
hystrix熔断机制修改配置
一、修改参数设置参数有3个地方:通过日志2018-02-1218:07:36.876DEBUGHystrixPropertiesChainedProperty:93-Flippingproperty:hystrix.command.HttpPostCommand.execution.isolation.thread.timeoutInMillisecondstouseNEXTproperty:hy 查看详情
springcloud总结21.单个feginclient禁用hystrix
接上篇《20.Feign对Hystrix的支持》 SpringCloud版本为Finchley.SR2版上一篇我们简单介绍了如何开启Feign对Hystrix的支持,并演示了实现FeignClient接口以及FallbackFactory接口两种形式的降级服务。下面我们来学习一下,在存在多... 查看详情
深入浅出springcloud原理及实战「netflix系列之hystrix」针对于限流熔断组件hystrix的基本参数和实现原理介绍分析(代码片段)
...章🏹【深入浅出SpringCloud原理及实战】「Netflix系列之Hystrix」针对于限流熔断组件Hystrix的基本参数和实现原理介绍分析在这里推荐给大家martinfowler的熔断器介绍和权威指南,有兴趣的小伙伴们可以研究一下哈。主要介绍相关... 查看详情
跟我学习springcloud教程第十篇:hystrix参数详解-b2b2c小程序电子商务(代码片段)
我们讨论了hystrix+feign+ribbon,但是可能很多人都知道hystrix还有线程隔离,信号量隔离,等等各种参数配置,在这几就记录下hystrix的参数,一、hystrix参数使用方法通过注解@HystrixCommand的commandProperties去配置,如下就是hystrix命令超... 查看详情
Hystrix 使用的 Bulkhead Pattern 是啥?
】Hystrix使用的BulkheadPattern是啥?【英文标题】:WhatisBulkheadPatternusedbyHystrix?Hystrix使用的BulkheadPattern是什么?【发布时间】:2015-08-0404:30:34【问题描述】:Hystrix是一种用于复杂分布式系统中的延迟和容错的NetflixAPI,它使用BulkheadP... 查看详情
转hystrix超时实现机制(代码片段)
HystrixCommand在执行的过程中如何探测超时,本篇主要对此进行介绍说明。1.主入口:executeCommandAndObserve#com.netflix.hystrix.AbstractCommand#executeCommandAndObserveprivateObservable<R>executeCommandAndObserve(finalAbstractComm 查看详情
hystrix属性配置策略
Hystrix属性配置 Command可配参数设置隔离策略execution.isolation.strategy=THREAD设置超时时间execution.isolation.thread.timeoutInMilliseconds=1000信号量隔离策略设置最大并发请求数(仅在信号量隔离策略下生效)execution.isolation.semaphore.maxConcurren 查看详情
hystrix学习使用
说明:每次调用创建一个新的HystrixCommand,把依赖调用封装在run()方法中执行execute()/queue做同步或异步调用请求接收后,会先看是否存在缓存数据,如果存在,则不会继续请求服务,直接返回缓存数据。如果不存在缓存数据,... 查看详情