在一种方法中,我创建一个新的RDD并将其缓存,在rdd超出范围后,Spark是否会自动取消保留RDD?
我是这样想的,但实际上是什么呢?
不,它不会自动取消保留。
为什么 ?因为也许您似乎不再需要RDD,但是spark模型是直到实现转换才需要实现RDD,所以实际上很难说出“我不再需要该RDD”了。即使对于您来说,由于以下情况,它也可能非常棘手:
JavaRDD<T> rddUnion = sc.parallelize(new ArrayList<T>()); // create empty for merging
for (int i = 0; i < 10; i++)
{
JavaRDD<T2> rdd = sc.textFile(inputFileNames[i]);
rdd.cache(); // Since it will be used twice, cache.
rdd.map(...).filter(...).saveAsTextFile(outputFileNames[i]); // Transform and save, rdd materializes
rddUnion = rddUnion.union(rdd.map(...).filter(...)); // Do another transform to T and merge by union
rdd.unpersist(); // Now it seems not needed. (But is needed actually)
// Here, rddUnion actually materializes, and needs all 10 rdds that already unpersisted. So, rebuilding all 10 rdds will occur.
rddUnion.saveAsTextFile(mergedFileName);
}
将代码示例归功于spark-user ml
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句