Hystrix Thread Pool Properties

13,790

You can define a properties file called config.properties that looks like:

    hystrix.threadpool.S1.coreSize=15
    hystrix.threadpool.S1.maximumSize=15
    hystrix.threadpool.S1.maxQueueSize=15
    hystrix.threadpool.S1.queueSizeRejectionThreshold=300
    hystrix.threadpool.S1.allowMaximumSizeToDivergeFromCoreSize=true
    hystrix.threadpool.S1.keepAliveTimeMinutes=1

    hystrix.threadpool.S2.coreSize=20
    hystrix.threadpool.S2.maximumSize=20
    hystrix.threadpool.S2.maxQueueSize=20
    hystrix.threadpool.S2.queueSizeRejectionThreshold=300
    hystrix.threadpool.S2.allowMaximumSizeToDivergeFromCoreSize=true
    hystrix.threadpool.S2.keepAliveTimeMinutes=1

...

Here is a nice explanation about the difference between coreSize, maximumSize & maxQueueSize:

https://github.com/Netflix/Hystrix/issues/1554

Share:
13,790
Timo Denk
Author by

Timo Denk

Updated on August 10, 2022

Comments

  • Timo Denk
    Timo Denk over 1 year

    In our application we use Hystrix because we call several external services. We want to configure one thread pool -- with a specific size -- for each external service that we call.

    Let's assume there are three external Services, called S1, S2, S3. Furthermore, we have 10 classes which extend HystrixCommand, called C1 through C10.

    C1 and C2 make calls to S1 and should use the same thread pool, with 15 threads. Inside the constructor of C1, we make the following call to super:

    super(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("S1"))
        .andThreadPoolKey(ThreadPools.S1)
        .andThreadPoolPropertiesDefaults(HystrixThreadPoolProperties.Setter().withCoreSize(15))
        .andCommandPropertiesDefaults(HystrixCommandProperties.Setter().withExecutionTimeoutInMilliseconds(timeout)));
    

    Inside the constructor of one command (C1) we specify the thread pool size for S1 to be 15. ThreadPools is a custom class where the final static attribute S1 is defined by

    S1 = HystrixThreadPoolKey.Factory.asKey("S1");
    

    Now the actual question is, (1) why the thread pool core size (for S1 it is 15) is specified inside a HystrixCommand instead of a central thread pool definition (which does not seem to be the concept of Hystrix).

    Suppose inside the constructor of C2 (which looks the same as the snippet above) we were to call withCoreSize with an argument other than 15. (2) Which one would be used?

    (3) Is there a way to define the three thread pools for the services S1, S2, and S3 in one class and reference them from the command classes?

    The Hystrix How to Use guide does not seem to contain information related to that. It would be great if someone had time to answer this question.

  • Timo Denk
    Timo Denk about 6 years
    Thanks for responding. Is there any documentation on the config.properties file available?
  • Lital Kolog
    Lital Kolog about 6 years