hystrix 配置

# 参考:https://github.com/Netflix/Hystrix/wiki/Configuration
#      https://www.cnblogs.com/throwable/p/11961016.html、
#      https://blog.csdn.net/tongtong_use/article/details/78611225

hystrix:
  # 一、命令配置
  command:
    # 默认全局配置
    default:
      # 1、命令执行(execution)配置
      execution:
        timeout:
          enabled: true   # 是否允许超时:true(默认值)、false
        isolation:
          strategy: THREAD   # 隔离策略:THREAD(默认值)、SEMAPHORE ---------【参考 ExecutionIsolationStrategy.THREAD】
          thread:
            interruptOnCancel: false    # 当发生取消时,执行是否应该中断:true、false(默认值)---------【THREAD模式有效】
            interruptOnTimeout: true    # 在发生超时时是否应中断:true(默认值)、false---------【THREAD模式有效】
            timeoutInMilliseconds: 1000   # 超时时间上限:单位是毫秒 默认1000---------【这个配置生效的前提是hystrix.command.default.execution.timeout.enabled或者hystrix.command.[HystrixCommandKey].execution.timeout.enabled为true; 在THREAD模式下,达到超时时间,可以中断,在SEMAPHORE模式下,会等待执行完成后,再去判断是否超时 设置标准:有retry,99meantime+avg meantime 没有retry,99.5meantime】
          semaphore:
            maxConcurrentRequests: 10    # 最大并发请求上限(SEMAPHORE):10(默认值);ExecutionIsolationStrategy.SEMAPHORE隔离策略下并发请求数量的最高上限
      # 2、命令降级(fallback)配置:对策略ExecutionIsolationStrategy.THREAD或者ExecutionIsolationStrategy.SEMAPHORE都生效
      fallback:
        enabled: true   # 是否开启降级:false、true(默认值)
        isolation:
          semaphore:
            maxConcurrentRequests: 10   # 最大并发降级请求处理上限:10(默认值)
      # 3、断路器(circuit breaker)配置
      circuitBreaker:
        enabled: true   # 是否启用断路器:false、true(默认值)
        requestVolumeThreshold: 10    # 断路器请求量阈值:20(默认值)---------【滑动窗口中的请求数量最少要达到这个阈值,断路器才可能被打开】
        sleepWindowInMilliseconds: 5000   # 断路器等待窗口时间:5000(默认值) ---------【断路器打开后,拒绝多长时间的请求】
        errorThresholdPercentage: 50    # 断路器错误百分比阈值:50(默认值) ---------【当请求错误率超过设定值,断路器就会打开】
        forceOpen: false   # 是否强制打开断路器:false(默认值)、true---------【强制打开断路器会使所有请求直接进入降级逻辑】
        forceClosed: false    # 是否强制关闭断路器:false(默认值)、true---------【强制关闭断路器会导致所有和断路器相关的配置和功能都失效】
      # 4、度量统计(metrics)配置:度量统计配置会对HystrixCommand或者HystrixObservableCommand执行时候的统计数据收集动作生效
      metrics:
        rollingStats:
          timeInMilliseconds: 10000   # 滑动窗口持续时间:10000(默认值)
          numBuckets: 10    # 滑动窗口Bucket总数:10(默认值)---------【需要满足metrics.rollingStats.timeInMilliseconds % metrics.rollingStats.numBuckets == 0,要尽量小,否则有可能影响性能】
        rollingPercentile:
          enabled: true   # 是否启用百分数计算:true(默认值)、false
          timeInMilliseconds: 60000   # 百分数计算使用的滑动窗口持续时间:60000(默认值)
          numBuckets: 6   # 百分数计算使用的Bucket总数:6(默认值)---------【满足metrics.rollingPercentile.timeInMilliseconds % metrics.rollingPercentile.numBuckets == 0,要尽量小,否则有可能影响性能】
          bucketSize: 100   # 百分数计算使用的Bucket容量:100(默认值)
        healthSnapshot:
          intervalInMilliseconds: 500   # 健康状态快照收集的周期:500(默认值)
      # 5、请求上下文配置:主要涉及到HystrixRequestContext和HystrixCommand的使用
      requestCache:
        enabled: true   # 是否启用请求缓存:true(默认值)、false
      requestLog:
        enabled: true   # 是否启用请求日志:true(默认值)、false
    # 实例配置
    CustomCommand:
      requestLog:
        enabled: true
      requestCache:
        enabled: true
      metrics:
        healthSnapshot:
          intervalInMilliseconds: 500
        rollingPercentile:
          bucketSize: 100
          numBuckets: 6
          timeInMilliseconds: 60000
          enabled: true
        rollingStats:
          numBuckets: 10
          timeInMilliseconds: 10000
      circuitBreaker:
        forceClosed: false
        forceOpen: false
        errorThresholdPercentage: 50
        sleepWindowInMilliseconds: 5000
        requestVolumeThreshold: 10
        enabled: true
      fallback:
        enabled: true
        isolation:
          semaphore:
            maxConcurrentRequests: 10
      execution:
        timeout:
          enabled: true
        isolation:
          semaphore:
            maxConcurrentRequests: 10
          thread:
            interruptOnCancel: false
            interruptOnTimeout: true
            timeoutInMilliseconds: 1000
          strategy=THREAD: THREAD
  # 二、请求合成器配置:主要控制HystrixCollapser的行为
  collapser:
    # 默认全局配置
    default:
      maxRequestsInBatch: 10     # 请求合成的最大批次量:Integer.MAX_VALUE (默认值)
      timerDelayInMilliseconds: 10    # 延迟执行时间:10(默认值)
      requestCache:
        enabled: true   # 是否启用请求合成缓存:true(默认值)、false
    # 实例配置
    CustomHystrixCollapser:
      requestCache:
        enabled: true
      timerDelayInMilliseconds: 10
      maxRequestsInBatch: 10
  # 三、线程池配置:Hystrix使用的是JUC线程池ThreadPoolExecutor,线程池相关配置直接影响ThreadPoolExecutor实例。Hystrix的命令执行选用了线程池策略,那么就是通过线程池隔离执行的,最好为每一个分组设立独立的线程池。笔者在生产实践的时候,一般把HystrixCommandGroupKey和HystrixThreadPoolKey设置为一致
  threadpool:
    # 默认全局配置
    default:
      coreSize: 10    # 核心线程数:10(默认值)
      maximumSize: 10   # 最大线程数:10(默认值)---------【此属性只有在allowMaximumSizeToDivergeFromCoreSize为true的时候才生效】
      maxQueueSize: -1    # 最大任务队列容量:-1(默认值)或者大于0的整数---------【配置为-1时使用的是SynchronousQueue,配置为大于1的整数时使用的是LinkedBlockingQueue;如果要从-1换成其他值则需重启,即该值不能动态调整】
      queueSizeRejectionThreshold: 5    # 任务拒绝的任务队列阈值:5(默认值)---------【当maxQueueSize配置为-1的时候,此配置项不生效】
      keepAliveTimeMinutes: 1   # 非核心线程存活时间:1(默认值)---------【当allowMaximumSizeToDivergeFromCoreSize为true并且maximumSize大于coreSize时此配置才生效】
      allowMaximumSizeToDivergeFromCoreSize: true   # 是否允许最大线程数生效:true、false(默认值)
      metrics:
        rollingStats:
          timeInMilliseconds: 10000   # 线程池滑动窗口持续时间: 10000(默认值)
          numBuckets: 10    # 线程池滑动窗口Bucket总数:10(默认值)---------【满足metrics.rollingStats.timeInMilliseconds % metrics.rollingStats.numBuckets == 0,值要尽量少,否则会影响性能】
    # 实例配置
    CustomCommand:
      metrics:
        rollingStats:
          numBuckets: 10
          timeInMilliseconds: 10000
      allowMaximumSizeToDivergeFromCoreSize: true
      keepAliveTimeMinutes: 1
      queueSizeRejectionThreshold: 5
      maxQueueSize: -1
      maximumSize: 10
      coreSize: 10
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值