spark中的cache() persist() checkpoint()之间的区别
来源:互联网 发布:java调用类的构造器 编辑:程序博客网 时间:2024/06/17 16:52
cache()与persist():
会被重复使用的(但是)不能太大的RDD需要cache。cache 只使用 memory,写磁盘的话那就叫 checkpoint 了。 哪些 RDD 需要 checkpoint?运算时间很长或运算量太大才能得到的 RDD,computing chain 过长或依赖其他 RDD 很多的 RDD。 实际上,将 ShuffleMapTask 的输出结果存放到本地磁盘也算是 checkpoint,只不过这个 checkpoint 的主要目的是去 partition 输出数据。
cache 机制是每计算出一个要 cache 的 partition 就直接将其 cache 到内存了。但 checkpoint 没有使用这种第一次计算得到就存储的方法,而是等到 job 结束后另外启动专门的 job 去完成 checkpoint 。 也就是说需要 checkpoint 的 RDD 会被计算两次。因此,在使用 rdd.checkpoint() 的时候,建议加上 rdd.cache(), 这样第二次运行的 job 就不用再去计算该 rdd 了,直接读取 cache 写磁盘。
cache 与 checkpoint 的区别:
关于这个问题,Tathagata Das 有一段回答: There is a significant difference between cache and checkpoint.Cache materializes the RDD and keeps it in memory and/or disk(其实只有 memory). But the lineage(也就是 computing chain) of RDD (that is, seq of operations that generated the RDD) will be remembered, so that if there are node failures and parts of the cached RDDs are lost, they can be regenerated. However, checkpoint saves the RDD to an HDFS file and actually forgets the lineage completely. This is allows longlineages to be truncated and the data to be saved reliably in HDFS (which is naturally fault tolerant by replication).
persist()与checkpoint()
参考:
会被重复使用的(但是)不能太大的RDD需要cache。cache 只使用 memory,写磁盘的话那就叫 checkpoint 了。 哪些 RDD 需要 checkpoint?运算时间很长或运算量太大才能得到的 RDD,computing chain 过长或依赖其他 RDD 很多的 RDD。 实际上,将 ShuffleMapTask 的输出结果存放到本地磁盘也算是 checkpoint,只不过这个 checkpoint 的主要目的是去 partition 输出数据。
cache 机制是每计算出一个要 cache 的 partition 就直接将其 cache 到内存了。但 checkpoint 没有使用这种第一次计算得到就存储的方法,而是等到 job 结束后另外启动专门的 job 去完成 checkpoint 。 也就是说需要 checkpoint 的 RDD 会被计算两次。因此,在使用 rdd.checkpoint() 的时候,建议加上 rdd.cache(), 这样第二次运行的 job 就不用再去计算该 rdd 了,直接读取 cache 写磁盘。
cache 与 checkpoint 的区别:
关于这个问题,Tathagata Das 有一段回答: There is a significant difference between cache and checkpoint.Cache materializes the RDD and keeps it in memory and/or disk(其实只有 memory). But the lineage(也就是 computing chain) of RDD (that is, seq of operations that generated the RDD) will be remembered, so that if there are node failures and parts of the cached RDDs are lost, they can be regenerated. However, checkpoint saves the RDD to an HDFS file and actually forgets the lineage completely. This is allows longlineages to be truncated and the data to be saved reliably in HDFS (which is naturally fault tolerant by replication).
persist()与checkpoint()
深入一点讨论,rdd.persist(StorageLevel.DISK_ONLY) 与 checkpoint 也有区别。前者虽然可以将 RDD 的 partition 持久化到磁盘,但该 partition 由 blockManager 管理。一旦 driver program 执行结束,也就是 executor 所在进程 CoarseGrainedExecutorBackend stop,blockManager 也会 stop,被 cache 到磁盘上的 RDD 也会被清空(整个 blockManager 使用的 local 文件夹被删除)。而 checkpoint 将 RDD 持久化到 HDFS 或本地文件夹,如果不被手动 remove 掉( 话说怎么 remove checkpoint 过的 RDD? ),是一直存在的,也就是说可以被下一个 driver program 使用,而 cached RDD 不能被其他 dirver program 使用。
使用checkpoint()的例子:
package internalsimport org.apache.spark.SparkContextimport org.apache.spark.SparkContext._import org.apache.spark.SparkConfobject groupByKeyTest { def main(args: Array[String]) { val conf = new SparkConf().setAppName("GroupByKey").setMaster("local") val sc = new SparkContext(conf) sc.setCheckpointDir("/Users/xulijie/Documents/data/checkpoint") val data = Array[(Int, Char)]((1, 'a'), (2, 'b'), (3, 'c'), (4, 'd'), (5, 'e'), (3, 'f'), (2, 'g'), (1, 'h') ) val pairs = sc.parallelize(data, 3) pairs.checkpoint pairs.count val result = pairs.groupByKey(2) result.foreachWith(i => i)((x, i) => println("[PartitionIndex " + i + "] " + x)) println(result.toDebugString) }}
参考:
http://www.tuicool.com/articles/qQ3eYv
0 0
- spark中的cache() persist() checkpoint()之间的区别
- spark中的cache() persist() checkpoint()之间的区别
- 【总结】论spark中的cache/persist/checkpoint
- Spark中cache和persist的区别
- spark cache和persist的区别
- Spark中persist和cache的区别
- Spark的cache和persist
- Spark RDD中cache和persist的区别
- Spark RDD中cache和persist的区别
- 2017.06.15--spark中cache和persist的区别
- 【Spark系列5】cache和persist的区别
- Spark的cache与checkpoint优化
- spark中的map和flattop,persist和cache分别有什么区别?
- spark cache persist
- spark cache和checkpoint
- Spark cache和checkpoint
- Hibernate 中的save和persist方法之间的区别
- 每次进步一点点——spark中cache和persist的区别
- hive使用经验总结(持续更新中)
- 约瑟夫环问题——链表
- Android-Button点击事件的四种写法
- 23种设计模式(13):迭代器模式
- 第五届“蓝桥杯”全国软件 校内选拔赛试题(Java组)2。
- spark中的cache() persist() checkpoint()之间的区别
- MySQL查询缓存设置提高MySQL查询性能
- 裁剪编译Linux Kernel 初识
- 有关ie下doctype被自动注释
- nginx配置了负载均衡后访问变的很慢解决方法
- 23种设计模式(14):解释器模式
- VC导出函数冲突
- 第五届“蓝桥杯”全国软件 校内选拔赛试题(Java组)3、求最大数约数
- niginx核心函数指令1:accept_mutex