繁体   English   中英

针对JavaRDD的每个操作的Apache Spark计时

[英]Apache Spark timing forEach operation on JavaRDD

问题:这是测试构建RDD所需时间的有效方法吗?

我在这里做两件事。 基本方法是,我们有M个实例(称为DropEvaluation)和N个DropResults。 我们需要将每个N DropResult与每个M DropEvaluations进行比较。 每个M必须看到每个N,以便最终获得M个结果。

如果在构建RDD之后不使用.count(),驱动程序将继续执行下一行代码,并说几乎没有时间来构建需要30分钟才能构建的RDD。

我只是想确保自己没有丢失任何东西,例如.count()可能需要很长时间? 我想计时.count(),我必须修改Spark的源代码?

M = 1000或2000。N = 10 ^ 7。

这实际上是笛卡尔问题-选择累加器是因为我们需要在适当的位置写入每个M。 建立完整的笛卡尔RDD也很丑陋。

我们建立了一个M累加器列表(不能用Java做一个列表累加器吗?)。 然后,我们使用foreach遍历RDD中的N个值。

澄清问题:正确计算了总时间,我问RDD上的.count()是否强制Spark等待RDD完成才可以进行计数。 .count()时间重要吗?

这是我们的代码:

// assume standin exists and does it's thing correctly

// this controls the final size of RDD, as we are not parallelizing something with an existing length
List<Integer> rangeN = IntStream.rangeClosed(simsLeft - blockSize + 1, simsLeft).boxed().collect(Collectors.toList());

// setup bogus array of size N for parallelize dataSetN to lead to dropResultsN       
JavaRDD<Integer> dataSetN = context.parallelize(rangeN);

// setup timing to create N
long NCreationStartTime = System.nanoTime();

// this maps each integer element of RDD dataSetN to a "geneDropped" chromosome simulation, we need N of these:
JavaRDD<TholdDropResult> dropResultsN = dataSetN.map(s -> standin.call(s)).persist(StorageLevel.MEMORY_ONLY());

// **** this line makes the driver wait until the RDD is done, right?
long dummyLength = dropResultsN.count();


long NCreationNanoSeconds = System.nanoTime() - NCreationStartTime;
double NCreationSeconds = (double)NCreationNanoSeconds / 1000000000.0;
double NCreationMinutes = NCreationSeconds / 60.0;

logger.error("{} test sims remaining", simsLeft);

// now get the time for just the dropComparison (part of accumulable's add)
long startDropCompareTime = System.nanoTime();

// here we iterate through each accumulator in the list and compare all N elements of dropResultsN RDD to each M in turn, our .add() is a custom AccumulableParam
for (Accumulable<TholdDropTuple, TholdDropResult> dropEvalAccum : accumList) {
    dropResultsN.foreach(new VoidFunction<TholdDropResult>() {
                    @Override
                    public void call(TholdDropResult dropResultFromN) throws Exception {
                            dropEvalAccum.add(dropResultFromN);
                    }
                });
            }

    // all the dropComparisons for all N to all M for this blocksize are done, check the time...
   long dropCompareNanoSeconds = System.nanoTime() - startDropCompareTime;
   double dropCompareSeconds = (double)dropCompareNanoSeconds / 1000000000.0;
    double dropCompareMinutes = dropCompareSeconds / 60.0;

    // write lines to indicate timing section
    // log and write to file the time for the N-creation

    ...

} // end for that goes through dropAccumList

Spark程序是惰性的,只有在调用RDD上的count之类的所有操作后,它才会运行。 您可以在Spark的文档中找到常见操作的列表

// **** this line makes the driver wait until the RDD is done, right?
long dummyLength = dropResultsN.count();

是的,在这种情况下, count强制计算dropResultsN ,因此将花费很长时间。 如果您进行第二次count ,由于RDD已被计算和缓存,它将很快返回。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM