SpringCloud微服务项目实战

# Hystrix 默认加载的配置文件 - 限流、 熔断
hystrix:
  # 线程池大小
  threadpool:
    default:
      coreSize: 1
      maxQueueSize: 200
      queueSizeRejectionThreshold: 2
 
    # 限流策略
    #如果没有定义HystrixThreadPoolKey,HystrixThreadPoolKey会默认定义为HystrixCommandGroupKey的值
    userGroup:
      coreSize: 1
      maxQueueSize: -1
      queueSizeRejectionThreshold:  800
 
 
    userThreadPool:
      coreSize: 1
      maxQueueSize: -1
      queueSizeRejectionThreshold:  800
 
# 执行策略
# 资源隔离模式,默认thread。还有一种叫信号量
  command:
    default:
      execution:
        isolation:
          strategy: THREAD
        # 是否打开超时
        timeout:
          enabled:  true
        # 超时时间,默认1000毫秒
        isolation:
          thread:
            timeoutInMilliseconds:  15000
            # 超时时中断线程
            interruptOnTimeout: true
            # 取消时候中断线程
            interruptOnFutureCancel: false
            # 信号量模式下,最大并发量
          semaphore:
            maxConcurrentRequests:  2
      # 降级策略
      # 是否开启服务降级
      fallback:
        enabled:  true
        # fallback执行并发量
        isolation:
          semaphore:
            maxConcurrentRequests:  100
      # 熔断策略
      # 启用/禁用熔断机制
      circuitBreaker:
        enabled:  true
        # 强制开启熔断
        forceOpen:  false
        # 强制关闭熔断
        forceClosed:  false
        # 前提条件,一定时间内发起一定数量的请求。也就是5秒钟内(这个5秒对应下面的滚动窗口长度)至少请求4次,熔断器才发挥起作用。默认20
        requestVolumeThreshold: 4
        # 错误百分比。达到或超过这个百分比,熔断器打开。比如:5秒内有4个请求,2个请求超时或者失败,就会自动开启熔断
        errorThresholdPercentage: 50
        # 10秒后,进入半打开状态(熔断开启,间隔一段时间后,会让一部分的命令去请求服务提供者,如果结果依旧是失败,则又会进入熔断状态,如果成功,就关闭熔断)。默认5秒
        sleepWindowInMilliseconds:  10000
 
      # 度量策略
      # 5秒为一次统计周期,术语描述:滚动窗口的长度为5秒
      metrics:
        rollingStats:
          timeInMilliseconds: 5000
          # 统计周期内 度量桶的数量,必须被timeInMilliseconds整除。作用:
          numBuckets: 10
        # 是否收集执行时间,并计算各个时间段的百分比
        rollingPercentile:
          enabled:  true
          # 设置执行时间统计周期为多久,用来计算百分比
          timeInMilliseconds: 60000
          # 执行时间统计周期内,度量桶的数量
          numBuckets: 6
          # 执行时间统计周期内,每个度量桶最多统计多少条记录。设置为50,有100次请求,则只会统计最近的10次
          bucketSize: 100
        # 数据取样时间间隔
        healthSnapshot:
          intervalInMilliseconds: 500
 
      # 设置是否缓存请求,request-scope内缓存
      requestCache:
        enabled:  false
      # 设置HystrixCommand执行和事件是否打印到HystrixRequestLog中
      equestLog:
          enabled:  false
          
  userCommandKey:
    execution:
      isolation:
        thread:
          timeoutInMilliseconds: 5000
————————————————
版权声明:本文为CSDN博主「键盘客」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/u011134780/article/details/107171958/
原文地址:https://www.cnblogs.com/roak/p/14893210.html