Tim*_*enk 5 java concurrency multithreading hystrix
在我们的应用程序中,我们使用Hystrix,因为我们调用了多个外部服务。我们想为我们调用的每个外部服务配置一个线程池(具有特定的大小)。
假设有三个外部服务,分别称为S1,S2,S3。此外,我们有10个扩展类HystrixCommand,称为C1至C10。
C1和C2调用S1,并且应使用具有15个线程的相同线程池。在C1的构造函数中,我们对进行以下调用super:
super(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("S1"))
.andThreadPoolKey(ThreadPools.S1)
.andThreadPoolPropertiesDefaults(HystrixThreadPoolProperties.Setter().withCoreSize(15))
.andCommandPropertiesDefaults(HystrixCommandProperties.Setter().withExecutionTimeoutInMilliseconds(timeout)));
Run Code Online (Sandbox Code Playgroud)
在一个命令(C1)的构造函数内部,我们将S1的线程池大小指定为15。这ThreadPools是一个自定义类,其中的final static属性S1由
S1 = HystrixThreadPoolKey.Factory.asKey("S1");
Run Code Online (Sandbox Code Playgroud)
现在的实际问题是:(1)为什么在a HystrixCommand而不是中央线程池定义(似乎不是Hystrix的概念)中指定线程池核心大小(对于S1为15 )。
假设在C2(与上面的代码段相同的)构造函数中,我们用一个非15的参数调用withCoreSize。(2)将使用哪个参数?
(3)有没有一种方法可以在一个类中为服务S1,S2和S3定义三个线程池,并从命令类中引用它们?
Hystrix的使用方法指南似乎不包含与此相关的信息。如果有人有时间回答这个问题,那就太好了。
您可以定义一个名为的属性文件config.properties,如下所示:
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
...
Run Code Online (Sandbox Code Playgroud)
这是关于 coreSize、maximumSize 和 maxQueueSize 之间差异的一个很好的解释:
https://github.com/Netflix/Hystrix/issues/1554
| 归档时间: |
|
| 查看次数: |
5104 次 |
| 最近记录: |