• 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 的线程数就可以释放调了。

  • 相关阅读:
    【转】Intellij IDEA常用配置详解
    scala(一)
    scala(三)
    Scrapy学习篇(六)之Selector选择器
    Scrapy学习篇(五)之Spiders
    Scrapy学习篇(四)之数据存储
    Scrapy学习篇(三)之创建项目
    Scrapy学习篇(二)之常用命令行工具
    Scrapy学习篇(一)之框架
    git实现github仓库和本地仓库同步
  • 原文地址:https://www.cnblogs.com/zhangjianbin/p/9077040.html
Copyright © 2020-2023  润新知