我有一个VM,它有两个CPU。
这里是VM的CPU信息:CPU:2__;在线CPU列表:0,1__;每个核心线程:1
运行webflux (它拥有运行在弹性()Scheduler上的1000个对象的ParallelFlux )应用程序。它总是只创建两个线程来执行流动中的对象。
尝试使用FromSchedular(Executors.newFixedThreadPool(500)),,仍然只创建2个线程。
:我需要增加虚拟机上的CPU吗?还是有其他解决方案?
public Flux<FieldResult> execute(List<Field> fieldList){
return Flux.fromIterable(fieldList)
.parallel()
.runOn(elastic())
.flatMap(field -> {
return processField(field);
});
}发布于 2020-06-18 08:53:11
默认情况下,Flux.parallel()创建的rails与有CPU核心的rails一样多。
要使用更多的rails,您需要使用Flux.parallel(int并行)。之后,您可以使用ParallelFlux.runOn(Schedulers.elastic())。
在你的例子中:
public ParallelFlux<FieldResult> execute(List<Field> fieldList){
return Flux.fromIterable(fieldList)
.parallel(fieldList.size())
.runOn(Schedulers.elastic())
.map(field -> {
return processField(field);
});
}发布于 2019-11-22 09:01:19
它将根据订阅者的数量创建线程。ElasticBounded()是首选方法。
并使用弹性维尔保护器,使每个订阅者获得自己的线程。
https://stackoverflow.com/questions/58981619
复制相似问题