gpt4 book ai didi

java - java的.asparallel()方法中的 'batchsize'是什么

转载 作者:行者123 更新时间:2023-12-01 17:49:30 25 4
gpt4 key购买 nike

Java,更具体地说是 eclipse 集合库,有一个名为...的方法

asparallel(ExecutorService ES, int batchSize)

它需要两个参数,如图所示。 batchSize 参数是什么?

背景

这不是 Activity 线程的数量。这是由 ExecutorService 定义的。为了说明这一点,这是我提供的代码的示意流程(无法分享更多)。

ExecutorService executor = Executors.newWorkStealingPool(pThreads);
List<Object> mParallelOutput = objectsOfInterest.toList()
.asParallel(executor, batchsize1)
.flatCollect(myObject-> MySubComponent.toList()
.asParallel(executor, batchsize2)
.flatCollect(p -> p.performComputation(myObject));

举个例子,我有“一堆”计算(performComputation()方法),需要对列表objectsOfInterest中的1-32个对象执行>。所有计算都可以并行完成,我们需要尽可能高效。在尝试理解流程时,我想知道 asparallel() 方法的 batchsize 参数是什么。另外,我不确定上面示例代码中对 asparallel 的双重调用是否有任何额外的好处。

最佳答案

来自https://github.com/eclipse/eclipse-collections/blob/master/docs/guide.md :

The batch size determines the number of elements from the backing collection (FastList or UnifiedSet) that get processed by each task submitted to the thread pool. Appropriate batch sizes for CPU-bound tasks are usually larger, in the 10,000 to 100,000 range.

因此,我得出结论,在您的情况下,batchSize = 1 是有意义的。 (完全并行)

或者:

 #tasks (submitted to the TP) = collection.size() / batchSize

据我了解,执行器的线程数是可以同时处理的任务数,我会“对齐”这两个值:#threads ~= #tasks

关于java - java的.asparallel()方法中的 'batchsize'是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60820161/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com