通过观察RDD.scala源代码即可知道cache和persist的区别:
|
def persist(newLevel: StorageLevel): this.type = {
sc.cleaner.foreach(_.registerRDDForCleanup(this))
/** Persist this RDD with the default storage level (`MEMORY_ONLY`). */
/** Persist this RDD with the default storage level (`MEMORY_ONLY`). */ |
可知:
1)RDD的cache()方法其实调用的就是persist方法,缓存策略均为MEMORY_ONLY;
2)可以通过persist方法手工设定StorageLevel来满足工程需要的存储级别;
3)cache或者persist并不是action;
附:cache和persist都可以用unpersist来取消

本文详细解释了Apache Spark中RDD的cache与persist方法的区别。cache实际上调用了persist方法,并默认使用MEMORY_ONLY存储级别。persist允许手动指定StorageLevel,以满足不同场景的需求。两者都不是action操作。
637

被折叠的 条评论
为什么被折叠?



