SpringCloud(六)Hystrix配置

摘要:
默认truehystrix.command.default.circuitBreaker.requestVolumeThreshold一个rollingwindow内最小的请求数。默认20hystrix.command.default.circuitBreaker.sleepWindowInMilliseconds触发短路的时间值,当该值设为5000时,则当触发circuitbreak后的5000毫秒内都会拒绝request,也就是5000毫秒后才会关闭circuit。默认50hystrix.command.default.circuitBreaker.forceOpen强制打开熔断器,如果打开这个开关,那么拒绝所有request,默认falsehystrix.command.default.circuitBreaker.forceClosed强制关闭熔断器如果这个开关打开,circuit将一直关闭且忽略circuitBreaker.errorThresholdPercentageMetrics相关参数hystrix.command.default.metrics.rollingStats.timeInMilliseconds设置统计的时间窗口值的,毫秒值,circuitbreak的打开会根据1个rollingwindow的统计来计算。若rollingwindow被设为10000毫秒,则rollingwindow会被分成n个buckets,每个bucket包含success,failure,timeout,rejection的次数的统计信息。

hystrix.command.default和hystrix.threadpool.default中的default为默认CommandKey

Execution相关的属性的配置:

hystrix.command.default.execution.isolation.strategy
隔离策略,默认是Thread, 可选Thread|Semaphore

hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds
命令执行超时时间,默认1000ms

hystrix.command.default.execution.timeout.enabled
执行是否启用超时,默认启用true

hystrix.command.default.execution.isolation.thread.interruptOnTimeout
发生超时是是否中断,默认true

hystrix.command.default.execution.isolation.semaphore.maxConcurrentRequests 最大并发请求数,默认10,该参数当使用ExecutionIsolationStrategy.SEMAPHORE策略时才有效。如果达到最大并发请求数,请求会被拒绝。理论上选择semaphore size的原则和选择thread size一致,但选用semaphore时每次执行的单元要比较小且执行速度快(ms级别),否则的话应该用thread。semaphore应该占整个容器(tomcat)的线程池的一小部分。

Fallback相关的属性
这些参数可以应用于Hystrix的THREAD和SEMAPHORE策略

hystrix.command.default.fallback.isolation.semaphore.maxConcurrentRequests 如果并发数达到该设置值,请求会被拒绝和抛出异常并且fallback不会被调用。默认10

hystrix.command.default.fallback.enabled
当执行失败或者请求被拒绝,是否会尝试调用hystrixCommand.getFallback() 。默认true

Circuit Breaker相关的属性

hystrix.command.default.circuitBreaker.enabled
用来跟踪circuit的健康性,如果未达标则让request短路。默认true

hystrix.command.default.circuitBreaker.requestVolumeThreshold
一个rolling window内最小的请求数。如果设为20,那么当一个rolling window的时间内(比如说1个rolling window是10秒)收到19个请求,即使19个请求都失败,也不会触发circuit break。默认20

hystrix.command.default.circuitBreaker.sleepWindowInMilliseconds
触发短路的时间值,当该值设为5000时,则当触发circuit break后的5000毫秒内都会拒绝request,也就是5000毫秒后才会关闭circuit。默认5000

hystrix.command.default.circuitBreaker.errorThresholdPercentage
错误比率阀值,如果错误率>=该值,circuit会被打开,并短路所有请求触发fallback。默认50

hystrix.command.default.circuitBreaker.forceOpen
强制打开熔断器,如果打开这个开关,那么拒绝所有request,默认false

hystrix.command.default.circuitBreaker.forceClosed
强制关闭熔断器 如果这个开关打开,circuit将一直关闭且忽略circuitBreaker.errorThresholdPercentage

Metrics相关参数

hystrix.command.default.metrics.rollingStats.timeInMilliseconds
设置统计的时间窗口值的,毫秒值,circuit break 的打开会根据1个rolling window的统计来计算。若rolling window被设为10000毫秒,则rolling window会被分成n个buckets,每个bucket包含success,failure,timeout,rejection的次数的统计信息。默认10000

hystrix.command.default.metrics.rollingStats.numBuckets
设置一个rolling window被划分的数量,若numBuckets=10,rolling window=10000,那么一个bucket的时间即1秒。必须符合rolling window % numberBuckets == 0。默认10

hystrix.command.default.metrics.rollingPercentile.enabled
执行时是否enable指标的计算和跟踪,默认true

hystrix.command.default.metrics.rollingPercentile.timeInMilliseconds 设置rolling percentile window的时间,默认60000

hystrix.command.default.metrics.rollingPercentile.numBuckets
设置rolling percentile window的numberBuckets。逻辑同上。默认6

hystrix.command.default.metrics.rollingPercentile.bucketSize
如果bucket size=100,window=10s,若这10s里有500次执行,只有最后100次执行会被统计到bucket里去。增加该值会增加内存开销以及排序的开销。默认100

hystrix.command.default.metrics.healthSnapshot.intervalInMilliseconds
记录health 快照(用来统计成功和错误绿)的间隔,默认500ms

Request Context 相关参数

hystrix.command.default.requestCache.enabled
默认true,需要重载getCacheKey(),返回null时不缓存

hystrix.command.default.requestLog.enabled
记录日志到HystrixRequestLog,默认true

Collapser Properties 相关参数

hystrix.collapser.default.maxRequestsInBatch
单次批处理的最大请求数,达到该数量触发批处理,默认Integer.MAX_VALUE

hystrix.collapser.default.timerDelayInMilliseconds
触发批处理的延迟,也可以为创建批处理的时间+该值,默认10

hystrix.collapser.default.requestCache.enabled
是否对HystrixCollapser.execute() and HystrixCollapser.queue()的cache,默认true

ThreadPool 相关参数

线程数默认值10适用于大部分情况(有时可以设置得更小),如果需要设置得更大,那有个基本得公式可以follow:
requests per second at peak when healthy × 99th percentile latency in seconds + some breathing room
每秒最大支撑的请求数 (99%平均响应时间 + 缓存值)
比如:每秒能处理1000个请求,99%的请求响应时间是60ms,那么公式是:
1000 (0.060+0.012)
基本得原则时保持线程池尽可能小,他主要是为了释放压力,防止资源被阻塞。
当一切都是正常的时候,线程池一般仅会有1到2个线程激活来提供服务

hystrix.threadpool.default.coreSize
并发执行的最大线程数,默认10

hystrix.threadpool.default.maxQueueSize
BlockingQueue的最大队列数,当设为-1,会使用SynchronousQueue,值为正时使用LinkedBlcokingQueue。该设置只会在初始化时有效,之后不能修改threadpool的queue size,除非reinitialising thread executor。默认-1。

hystrix.threadpool.default.queueSizeRejectionThreshold
即使maxQueueSize没有达到,达到queueSizeRejectionThreshold该值后,请求也会被拒绝。因为maxQueueSize不能被动态修改,这个参数将允许我们动态设置该值。if maxQueueSize == -1,该字段将不起作用

hystrix.threadpool.default.keepAliveTimeMinutes
如果corePoolSize和maxPoolSize设成一样(默认实现)该设置无效。如果通过plugin(https://github.com/Netflix/Hystrix/wiki/Plugins)使用自定义实现,该设置才有用,默认1.

hystrix.threadpool.default.metrics.rollingStats.timeInMilliseconds
线程池统计指标的时间,默认10000

hystrix.threadpool.default.metrics.rollingStats.numBuckets
将rolling window划分为n个buckets,默认10

免责声明:文章转载自《SpringCloud(六)Hystrix配置》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇iOS--Block的那些事仿知乎网站下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

SpringCloud之Hystrix熔断降级(六)

前言 Hystrix是一个用于处理分布式系统的延迟和容错和开源库,在分布式系统里,许多依赖不可避免的会调用失败,比如超时,异常等,Hystrix能保证在一个依赖出现问题的情况下,不会导致整体服务失败,避免级联故障,以提高分布式系统的弹性; “断路器”本身是一种开关装置,当某个服务单元发生故障之后,通过断路器的故障 监控(类似熔断保险丝),向调用方返回一个符...

Prometheus Node_exporter 之 Network Netstat UDP

Network Netstat UDP /proc/net/snmp 1. UDP In / Out type: GraphUnit: shortLabel: Datagrams out (-) / in (+)InDatagrams - 平均接收的 UDP 数据包(5分钟内)metrics: irate(node_netstat_Udp_InDatagr...

spring Cloud中,解决Feign/Ribbon整合Hystrix第一次请求失败的问题?

Spring Cloud中,Feign和Ribbon在整合了Hystrix后,可能会出现首次调用失败的问题,要如何解决该问题呢? 造成该问题的原因 Hystrix默认的超时时间是1秒,如果超过这个时间尚未响应,将会进入fallback代码。而首次请求往往会比较慢(因为Spring的懒加载机制,要实例化一些类),这个响应时间可能就大于1秒了。知道原因后,我们...

SpringCloud Feign 之 超时重试次数探究

SpringCloud Feign 之 超时重试次数探究 上篇文章,我们对Feign的fallback有一个初步的体验,在这里我们回顾一下,Fallback主要是用来解决依赖的服务不可用或者调用服务失败或超时,使用默认的返回值。实际应用中, 在Fallback之前,需要对服务配置重试机制,当多次重试服务,还是服务不可用的情况下,就触发Fallback。 这...

Spring Boot Actutaur + Telegraf + InFluxDB + Grafana 构建监控平台

完成一套精准,漂亮图形化监控系统从这里开始第一步 为啥选择这些组件 Jolokia: Spring Boot 认可使用Jolokia来通过HTTP导出export JMX数据。你只需要在工程类路径中增加一些依赖项,一切都是开箱即用的。不需要任何额外的实现。 Telegraf: Telegraf支持通过整合Jolokia来集成JMX数据的收集。它有一个预...

如何处理CrashLoopBackOff状态的pod

问题现状 集群在初始化时,发现有几个基础组件的pod未能成功启动,现象如下: 定位问题 查看pod的状态 [root@iZwj205uppsujnphknhb3wZ ~]# kubectl describe pod metrics-server-697c65d5ff-cspzn -n kube-system 然后查看日志,看看是什么错误导致的 [roo...