RDD中cache和persist的区别

Posted timssd

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了RDD中cache和persist的区别相关的知识,希望对你有一定的参考价值。

 

RDD中cache和persist的区别

  

通过观察RDD.scala源代码即可知道cache和persist的区别:

def persist(newLevel: StorageLevel): this.type =
  if (storageLevel != StorageLevel.NONE && newLevel != storageLevel)
    throw new UnsupportedOperationException( "Cannot change storage level of an RDD after it was already assigned a level")
  
  sc.persistRDD(this)

  sc.cleaner.foreach(_.registerRDDForCleanup(this))
  storageLevel = newLevel
  this

/** Persist this RDD with the default storage level (`MEMORY_ONLY`). */
def persist(): this.type = persist(StorageLevel.MEMORY_ONLY)

 

/** Persist this RDD with the default storage level (`MEMORY_ONLY`). */
def cache(): this.type = persist()

以上是关于RDD中cache和persist的区别的主要内容,如果未能解决你的问题,请参考以下文章

缓存和持久化有啥区别?

RDD的cachepersistcheckpoint的区别和StorageLevel存储级别划分

Spark的算子(函数)

Spark(13)——cache和chickpoint的区别

大数据之Spark:Spark面试(高级)

Spark RDD Transformation 简单用例