美文网首页
Hystrix相关配置项整理(spring cloud Edgw

Hystrix相关配置项整理(spring cloud Edgw

作者: 花花大脸猫 | 来源:发表于2019-12-15 12:16 被阅读0次

以下内容为服务使用hystrix的相关配置明细整理,高版本可能有些许差异。如有不对之处,还望指出,多谢。

以调用User为例说明如下:

相关源码配置分别在如下两个类中HystrixThreadPoolProperties,HystrixCommandProperties

#hystrix线程池相关配置

#设置allowMaximumSizeToDivergeFromCoreSize值为true时,线程池的maximumSize才有作用

hystrix.threadpool.User-SERVICE.allowMaximumSizeToDivergeFromCoreSize=true

hystrix.threadpool.default.allowMaximumSizeToDivergeFromCoreSize=false

#设置线程池的coresize核心线程池数量,默认为10

hystrix.threadpool.User-SERVICE.coreSize = 20

hystrix.threadpool.default.coreSize = 10

#设置线程池的maximumSize数量,默认也为10

hystrix.threadpool.User-SERVICE.maximumSize=100

hystrix.threadpool.default.maximumSize=10

#线程池中maximumSize-coresize数量之后,剩余线程的回收空闲时间,单位为分钟,默认为一分钟

hystrix.threadpool.User-SERVICE.keepAliveTimeMinutes=1

hystrix.threadpool.default.keepAliveTimeMinutes= 1

#线程池中的等待队列,默认为-1,由SynchronousQueue作为队列实现,当为正整数时,使用LinkedBlockingQueue,

hystrix.threadpool.User-SERVICE.maxQueueSize = 20

hystrix.threadpool.default.maxQueueSize=-1

#因为maxQueueSize值不能被动态修改,所有通过设置此值可以实现动态修改等待队列长度。即等待的队列的数量大于queueSizeRejectionThreshold时(但是没有达到maxQueueSize值),则开始拒绝后续的请求进入队列。

#如果设置-1,则属性不启作用,默认值:5

hystrix.threadpool.User-SERVICE.queueSizeRejectionThreshold = 5

hystrix.threadpool.default.queueSizeRejectionThreshold = 5

#设置滚动窗口的时间,按照默认值设置即可,无需单独设置,默认为10000(10)秒滚动窗口统计时间

hystrix.threadpool.User-SERVICE.metrics.rollingStats.timeInMilliseconds=10000

hystrix.threadpool.default.metrics.rollingStats.timeInMilliseconds=10000

#设置滚动静态窗口分成的桶的数量,按照默认值设置即可,无需单独设置,默认为10个桶

hystrix.threadpool.User-SERVICE.metrics.rollingStats.numBuckets=10

hystrix.threadpool.default.metrics.rollingStats.numBuckets=10

#HystrixCommand相关配置,默认隔离级别为thread,只讨论thread级别相关配置项,与具体的feign客户端定义的方法有关系,以下举例说明

#是否开启断路器功能,具体到每一个方法级别,默认启用true,按照默认值设置即可,无需单独设置

hystrix.command.IUserClient#listAllPaymentProduct().circuitBreaker.enabled=true

hystrix.command.default.circuitBreaker.enabled=true

#该属性设置滚动窗口中将使断路器跳闸的最小请求数量如果此属性值为20,则在窗口时间内(如10s内),如果只收到19个请求且都失败了,则断路器也不会开启,按照默认值设置即可,无需单独设置

hystrix.command.IUserClient#listAllPaymentProduct().circuitBreaker.requestVolumeThreshold = 20

hystrix.command.default.circuitBreaker.requestVolumeThreshold = 20

#断路器跳闸后,在此设置值的时间的内,hystrix会拒绝新的请求,只有过了这个时间断路器才会打开闸门,默认为5000(5秒),按照默认值设置即可,无需单独设置

hystrix.command.IUserClient#listAllPaymentProduct().circuitBreaker.sleepWindowInMilliseconds=5000

hystrix.command.default.circuitBreaker.sleepWindowInMilliseconds=5000

#设置失败百分比的阈值。如果失败比率超过这个值,则断路器跳闸并且进入fallback逻辑,默认百分比为50%,按照默认值设置即可,无需单独设置

hystrix.command.IUserClient#listAllPaymentProduct().circuitBreaker.errorThresholdPercentage=50

hystrix.command.default.circuitBreaker.errorThresholdPercentage=50

#如果设置true,则强制使断路器跳闸,则会拒绝所有的请求.此值会覆盖circuitBreaker.forceClosed的值,默认为false,按照默认值设置即可,无需单独设置

hystrix.command.IUserClient#listAllPaymentProduct().circuitBreaker.forceOpen=false

hystrix.command.default.circuitBreaker.forceOpen=false

#如果设置true,则强制使断路器进行关闭状态,此时会允许执行所有请求,无论是否失败的次数达到circuitBreaker.errorThresholdPercentage值,默认为false,按照默认值设置即可,无需单独设置

hystrix.command.IUserClient#listAllPaymentProduct().circuitBreaker.forceClosed=false

hystrix.command.default.circuitBreaker.forceClosed=false

#在默认情况下,推荐HystrixCommands 使用 thread 隔离策略,HystrixObservableCommand 使用 semaphore 隔离策略。只有在高并发(单个实例每秒达到几百个调用)的调用时,才需要修改HystrixCommands 的隔离策略为semaphore 。semaphore 隔离策略通常只用于非网络调用

#按照默认值设置即可,无需单独设置

hystrix.command.IUserClient#listAllPaymentProduct().execution.isolation.strategy = THREAD

hystrix.command.default.execution.isolation.strategy = THREAD

#设置调用者执行的超时时间(单位毫秒),默认为1000(1秒),可根据具体方法进行设置

hystrix.command.IUserClient#listAllPaymentProduct().execution.isolation.thread.timeoutInMilliseconds=1000

hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=1000

#表示是否开启超时设置,默认为true,开启。按照默认值设置即可,无需单独设置

hystrix.command.IUserClient#listAllPaymentProduct().execution.timeout.enabled=true

hystrix.command.default.execution.timeout.enabled=true

#表示设置是否在执行超时时,中断HystrixCommand.run() 的执行,默认为true。按照默认值设置即可,无需单独设置

hystrix.command.IUserClient#listAllPaymentProduct().execution.isolation.thread.interruptOnTimeout=true

hystrix.command.default.execution.isolation.thread.interruptOnTimeout=true

#当隔离策略为THREAD时,当执行线程执行超时时,是否进行中断处理,即Future#cancel(true)处理,默认为false。按照默认值设置即可,无需单独设置

hystrix.command.IUserClient#listAllPaymentProduct().execution.isolation.thread.interruptOnFutureCancel=false

hystrix.command.default.execution.isolation.thread.interruptOnFutureCancel=false

#当HystrixCommand.run()使用SEMAPHORE的隔离策略时,设置最大的并发量,默认为10个,由于目前只设置Thread隔离级别,暂时只做了解

hystrix.command.IUserClient#listAllPaymentProduct().execution.isolation.semaphore.maxConcurrentRequests=10

hystrix.command.default.execution.isolation.semaphore.maxConcurrentRequests=10

#属性设置从调用线程允许HystrixCommand.getFallback()方法允许的最大并发请求数如果达到最大的并发量,则接下来的请求会被拒绝并且抛出异常.默认为10,由于目前只设置Thread隔离级别,暂时只做了解

hystrix.command.IUserClient#listAllPaymentProduct().fallback.isolation.semaphore.maxConcurrentRequests=10

hystrix.command.default.fallback.isolation.semaphore.maxConcurrentRequests=10

#是否开启fallback功能,默认为true。按照默认值设置即可,无需单独设置

hystrix.command.IUserClient#listAllPaymentProduct().fallback.enabled=true

hystrix.command.default.fallback.enabled=true

#设置滚动窗口的时间,按照默认值设置即可,无需单独设置,默认为10000(10)秒滚动窗口统计时间,针对具体的方法进行设置,

hystrix.command.IUserClient#listAllPaymentProduct().metrics.rollingStats.timeInMilliseconds=10000

hystrix.command.default.metrics.rollingStats.timeInMilliseconds=10000

#是否开启断路器功能,具体到每一个方法级别,默认启用true,按照默认值设置即可,无需单独设置

hystrix.command.IUserClient#listAllPaymentProduct().circuitBreaker.enabled=true

hystrix.command.default.circuitBreaker.enabled=true

#设置滚动静态窗口分成的桶的数量,按照默认值设置即可,无需单独设置,默认为10个桶,具体到每一个方法设置

hystrix.command.IUserClient#listAllPaymentProduct().metrics.rollingStats.numBuckets=10

hystrix.command.default.metrics.rollingStats.numBuckets=10

#设置执行延迟是否被跟踪,并且被计算在失败百分比中。默认为true,如果设置为false,则所有的统计数据返回-1

hystrix.command.IUserClient#listAllPaymentProduct().metrics.rollingPercentile.enabled=true

hystrix.command.default.metrics.rollingPercentile.enabled=true

#此属性设置统计滚动百分比窗口的持续时间,默认为60000(60秒)

hystrix.command.IUserClient#listAllPaymentProduct().metrics.rollingPercentile.timeInMilliseconds=60000

hystrix.command.default.metrics.rollingPercentile.timeInMilliseconds=60000

#设置统计滚动百分比窗口的桶数量,默认值为6

hystrix.command.IUserClient#listAllPaymentProduct().metrics.rollingPercentile.numBuckets=6

hystrix.command.default.metrics.rollingPercentile.numBuckets=6

#此属性设置每个桶保存的执行时间的最大值,默认值为100。如果桶数量是100,统计窗口为10s,如果这10s里有500次执行,只有最后100次执行会被统计到bucket里去

hystrix.command.IUserClient#listAllPaymentProduct().metrics.rollingPercentile.bucketSize=100

hystrix.command.default.metrics.rollingPercentile.bucketSize=100

#采样时间间隔,默认值为500

hystrix.command.IUserClient#listAllPaymentProduct().metrics.healthSnapshot.intervalInMilliseconds=500

hystrix.command.default.metrics.healthSnapshot.intervalInMilliseconds=500

#是否开启请求缓存功能,默认为true

hystrix.command.IUserClient#listAllPaymentProduct().requestCache.enabled=true

hystrix.command.default.requestCache.enabled=true

#表示是否开启日志,打印执行HystrixCommand的情况和事件,默认为true

hystrix.command.IUserClient#listAllPaymentProduct().requestLog.enabled=true

hystrix.command.default.requestLog.enabled=true

相关文章

网友评论

      本文标题:Hystrix相关配置项整理(spring cloud Edgw

      本文链接:https://www.haomeiwen.com/subject/qemknctx.html