hystrix线程池隔离源码初识

本文详细介绍了Hystrix的线程池隔离,包括HystrixCommand的初始化、线程池的配置参数如超时时间、核心线程数、队列大小和断路器策略等,并解析了HystrixThreadPool的初始化过程。
摘要由CSDN通过智能技术生成

hystrix源码初识之线程池隔离


本篇博客只讲述如下内容:


  • hystrixCommand的初始化过程
  • hystrix的线程池部分的初始化

一个DubboHystrixCommand构造过程如下

public DubboHystrixCommand(Invoker invoker, Invocation invocation) {

        super(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey(invoker.getInterface().getName()))
                .andCommandKey(HystrixCommandKey.Factory.asKey(String.format("%s_%d", invocation.getMethodName(),
                        invocation.getArguments() == null ? 0 : invocation.getArguments().length)))
                .andCommandPropertiesDefaults(
                        HystrixCommandProperties.Setter().withCircuitBreakerRequestVolumeThreshold(300)// 10秒钟内至少19此请求失败,熔断器才发挥起作用
                                .withCircuitBreakerSleepWindowInMilliseconds(1000)// 熔断器中断请求1秒后会进入半打开状态,放部分流量过去重试
                                .withCircuitBreakerErrorThresholdPercentage(50)// 错误率达到50开启熔断保护
                                .withExecutionTimeoutEnabled(false))// 使用dubbo的超时,禁用这里的超时
                .andThreadPoolPropertiesDefaults(
                        HystrixThreadPoolProperties.Setter().withCoreSize(getThreadPoolCoreSize(invoker.getUrl()))
                                .withMaxQueueSize(1000).withQueueSizeRejectionThreshold(700)));// 线程池为30
        this.invoker = invoker;
        this.invocation = invocation;
    }

setter为HystrixCommand的一个静态内部类:

这里写图片描述实际调用的构造方法为:

 /**
     * Construct a {
  @link HystrixCommand} with defined {
  @link Setter} that allows injecting property and strategy overrides and other optional arguments.
     * <p>
     * NOTE: The {
  @link HystrixCommandKey} is used to associate a {
  @link HystrixCommand} with {
  @link HystrixCircuitBreaker}, {
  @link HystrixCommandMetrics} and other objects.
     * <p>
     * Do not create multiple {
  @link HystrixCommand} implementations with the same {
  @link HystrixCommandKey} but different injected default properties as the first instantiated will win.
     * <p>
     * Properties passed in via {
  @link Setter#andCommandPropertiesDefaults} or {@link Setter#andThreadPoolPropertiesDefaults} are cached for the given {@link HystrixCommandKey} for the life of the JVM
     * or until {
  @link Hystrix#reset()} is called. Dynamic properties allow runtime changes. Read more on the <a href="https://github.com/Netflix/Hystrix/wiki/Configuration">Hystrix Wiki</a>.
     * 
     * 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值