Hystrix常用熔断参数

SpringCloud系列目录:


    @HystrixCommand(fallbackMethod = "str_fallbackMethod",
            groupKey = "strGroupCommand",
            commandKey = "strCommard",
            threadPoolKey = "strThreadPool",
            commandProperties = {
                    //设置隔离策略,THREAD表示线程池SEMAPHORE:信号地隔离
                    @HystrixProperty(name = "execution.isolation. strategy", value = "THREAD"),
                    //当隔离策略选择信号地隔离的时候,用来没置信号地的大小(最大并发数)
                    @HystrixProperty(name = "execution.isolation. semaphore.maxConcurrentRequests", value = "10"),
                    //配置命令执行的超时时间
                    @HystrixProperty(name = "execution.isolation.thread.timeoutinMilliseconds", value = "10"),
                    //悬否启用超时时间
                    @HystrixProperty(name = "execution.timeout. enabled", value = "true"),
                    //执行超时的时候是否中断
                    @HystrixProperty(name = "execution.isolation.thread.interruptOnTimeout", value = "true"),
                    //执行被取消的时候是否中断
                    @HystrixProperty(name = "execution.isolation.thread. interruptOnCancel", value = "true"),
                    //允许回调方法执行的最大并发数
                    @HystrixProperty(name = "fallback.isolation.semaphore.maxConcurrentRequests", value = "10"),
                    //服务降级是否启用,是否执行回湖函数
                    @HystrixProperty(name = "fallback.enabled", value = "true"),
                    @HystrixProperty(name = "circuitBreaker.enabled", value = "true"),
                    //该属性用来设置在演动时间窗中,断路器熔断的最小请求数。例如,默认该值为20的时候,
                    //如果滚动时间窗(默认10秒)内仅收到719个请求,即使这19个请求都失败了,断路器也不会打开。
                    @HystrixProperty(name = "circuitBreaker.requestVolumeThreshold", value = "20"),
                    //该属性用来设置在模动时间窗中,表示在滚动时间窗中,在请求数量超过
                    // circuitBreaker. requestVolumeThreshold的情况下,如果错误请求数的百分比超过50,
                    //就把断路器设置为“打开"状态,否则就设置为“关闭"状态。
                    @HystrixProperty(name = "circuitBreaker.errorThresholdPercentage", value = "50"),
                    //该属性用来设置当断路器打开之后的休眠时间窗。休眠时间窗结束之后,
                    //会将断路器置为“半开"状态,尝式熔断的请求命令,如果依然失败就将断路器继续设置为“打开"状态,
                    //如果成功就设置为“关闭"状态。
                    @HystrixProperty(name = "circuitBreaker.sleeplindowinMilliseconds", value = "5000"),
                    //断路器强制打开
                    @HystrixProperty(name = "circuitBreaker.forceOpen", value = "false"),
                    //断路器强制关闭
                    @HystrixProperty(name = "circuitBreaker.forceClosed", value = "false"),
                    //滚动时间窗设置,该时间用于断路器判断健康度时需要收集信息的持续时间
                    @HystrixProperty(name = "metrics.rollingStats.timeinMilliseconds", value = "10000"),
                    //该属性用来设置凝动时间窗统计指标信息时划分"镑"的数量,断路器在收集指标信息的时候会根据//设置的时间窗长度拆分成多个“裙"来翼计各度量值,每个"裙"记录了一段时间内的采集指标。//比如10秒内拆分成10个“裤”收集这样,所以timeinilliseconds 必须能被numBuckets 整除。 否则会抛异常
                    @HystrixProperty(name = "metrics.rollingStats.numBuckets", value = "10"),
                    //动时间窗设置,该时间用于断路器判断健康度时需要收集信息的持续时间
                    @HystrixProperty(name = "metrics.rollingStats.timeinMilliseconds", value = "10000"),
                    //该属性用来设置模动时间窗统计指标信息时划分"榜"的数量,断路器在收集指标信息的时候会根据
                    //设置的时间窗长度拆分成多个“裤"来累计各度量值,每个"榜”记录了一段时间内的采集指标。
                    //比如10秒内拆分成10个"榜"收集这样,所以timeinMilliseconds必须能被numBuckets整除。否则会抛异常
                    @HystrixProperty(name = "metrics.rollingStats. numBuckets", value = "10"),
                    //该属性用来设置对命令执行的延迟是否使用百升位数来跟踪和计算。如果设置为false,那么所有的概要统计都将返回-1.
                    @HystrixProperty(name = "metrics.rollingPercentile. enabled", value = "false"),
                    //该属性用来设置百分位统计的凝动窗口的持续时间,单位为喜秒。
                    @HystrixProperty(name = "metrics.rollingPercentile.timeInMilliseconds", value = "6000e"),
                    //该属性用央设置百分位统计模动窗口中使用“榜”的数量
                    @HystrixProperty(name = "metrics.rollingPercentile. numBuckets", value = "60000"),
                    //该属性用来设置在执行过程中每个“桶”中保留的最大执行次数。如果在模动时间窗内发生超过该设定值的执行况数,
                    //就从最初的位置开始重写。例如,将该值设置为100,滚动窗口为10秒,若在10秒内一个“捅”中发生了500次执行
                    //那么该“桶”中只保留最后的100,次执行的统计。另外,增加该值的大小将会增加内存量的消耗,并增加排序百分位数所需的计算时间。
                    @HystrixProperty(name = "metrics.rollingPercentile. bucketSize", value = "100"),
                    //该属性用来设置采集影响断路器状态的健康快照(请求的成功、错误百分比)的间隔等待时间。
                    @HystrixProperty(name = "metrics. healthSnapshot.intervalinMilliseconds", value = "500"),
                    //悬否开启请求缓存
                    @HystrixProperty(name = "requestCache. enabled", value = "true"),
                    // HystrixCommand的执行和事件悬否打印日志到HystrixRequestLog中
                    @HystrixProperty(name = "requestLog.enabled", value = "true"),
                    @HystrixProperty(name = "metrics.rollingPercentile.bucketSize", value = "100"),
                    //该属性用夹设置采集影响断路器状态的健康快照(请求的成功、错误百分比)的间隔等待时间。
                    @HystrixProperty(name = "metrics. healthSnapshot.intervalinMilliseconds", value = "500"),
                    //是否开启请求缓存
                    @HystrixProperty(name = "requestCache.enabled", value = "true"),
                    // Hystrixcommand的执行和事件是否打印日志到HystrixRequestLog中
                    @HystrixProperty(name = "requestLog. enabled", value = "true"),
            },
            threadPoolProperties = {
                    //该参数用来设置执行命令线程地的核心线程数,该值也就是命令执行的最大并发量
                    @HystrixProperty(name = "coreSize", value = "10"),
                    //该参数用来设置线程池的最大队列大小。当没置为-1时,线程池将使用SynchronousQueue实现的队列
                    //否则将使用LinkedBlockingQueue实现的队列。
                    @HystrixProperty(name = "maxQueuesize", value = "-1"),
                    //该参数用来为队列设置拒绝阈值。通过该参数,即使队列没有达到最大值也能拒绝请求。
                    //该参数主要是对LinkedBlockingQueue队列的补充,因为LinkedBlockingQueue
                    //队列不能动态修改它的对象大小,而通过该属性就可以调整拒绝请求的队列大小了。
                    @HystrixProperty(name = "queueSizeRejectionThreshold", value = "5")
            })
    public String paymentInfo_Timeout(Integer id) {
        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return "线程池" + Thread.currentThread().getName() + " id" + id;
    }
  • 5
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值