feign hystrix 线程池伸缩控制

当前使用的版本

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.3.RELEASE</version>
    </parent>
    
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Camden.SR7</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

相关依赖

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-hystrix</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>com.netflix.hystrix</groupId>
                    <artifactId>hystrix-core</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        
        <!-- 升级版本, keepAliveTimeMinutes 参数在 1.5.9版本以才能使用 -->
        <dependency>
            <groupId>com.netflix.hystrix</groupId>
            <artifactId>hystrix-core</artifactId>
            <version>1.5.10</version>
        </dependency>

某个服务 feign 接口并发参数,当没有队列的情况下

# 最小线程数
hystrix.threadpool.inventory-service.coreSize=5
# 最大线程数
hystrix.threadpool.inventory-service.maximumSize=20
# 线程在被释放之前将使用多长时间
hystrix.threadpool.inventory-service.keepAliveTimeMinutes=1
# 设为 true ,允许设置最小线程数 和 最大线程数
hystrix.threadpool.inventory-service.allowMaximumSizeToDivergeFromCoreSize=true

结论

在没有设置队列的情况下,一共有 25 个并发请求,则 5 个请求会被拒绝,只能一次通过 20 个请求,当 1 分钟后,则 线程池大小就会变为 5 个。这样大小coreSize 的线程数就可以释放调了。

原文地址:https://www.cnblogs.com/zhangjianbin/p/9077040.html