RDD中的cache() persist() checkpoint()
cache只有一个默认的缓存级别MEMORY_ONLY ,而persist可以根据StorageLevel设置其它的缓存级别。 cache以及persist都不是action。
被重复使用的(但是)不能太大的RDD需要cache
cache 只使用 memory,checkpoint写磁盘
rdd.persist(StorageLevel.DISK_ONLY) 与 checkpoint 的区别:
persist将 RDD 的 partition 持久化到磁盘,但该 partition 由 blockManager 管理。一旦 driver program 执行结束,也就是 executor 所在进程 CoarseGrainedExecutorBackend stop,blockManager 也会 stop,被 cache 到磁盘上的 RDD 也会被清空,而 checkpoint 将 RDD 持久化到 HDFS 或本地文件夹,如果不被手动 remove 掉,是一直存在的,也就是说可以被下一个 driver program 使用,而 cached RDD 不能被其他 dirver program 使用。
使用checkponint首先需要设置setCheckpointDir
scala> bb.checkpoint
org.apache.spark.SparkException: Checkpoint directory has not been set in the SparkContext
at org.apache.spark.rdd.RDD.checkpoint(RDD.scala:1544)
at org.apache.spark.sql.Dataset.checkpoint(Dataset.scala:517)
at org.apache.spark.sql.Dataset.checkpoint(Dataset.scala:502)
... 48 elided
创建文件夹(可不创建)
[root@host ~]# hdfs dfs -mkdir /tmp/checkpoint
scala> sc.setCheckpointDir("/tmp/checkpoint")
[root@host ~]# hdfs dfs -ls -R /tmp/checkpoint
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/root/hadoop/hadoop-2.7.4/share/hadoop/common/lib/slf4j-log4j12-1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/root/hive/apache-hive-2.1.1/lib/log4j-slf4j-impl-2.4.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
drwxr-xr-x - root supergroup 0 2018-07-31 17:33 /tmp/checkpoint/68309a1b-6e2d-4d03-8282-60abbbc8845b
scala> bb.checkpoint
res25: org.apache.spark.sql.Dataset[org.apache.spark.sql.Row] = [sex: int, count(1): bigint]
Dataset使用checkpoint不是lazy的,RDD使用checkpoint是lazy的
[root@host ~]# hdfs dfs -ls -R /tmp/checkpoint
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/root/hadoop/hadoop-2.7.4/share/hadoop/common/lib/slf4j-log4j12-1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/root/hive/apache-hive-2.1.1/lib/log4j-slf4j-impl-2.4.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
drwxr-xr-x - root supergroup 0 2018-07-31 17:35 /tmp/checkpoint/68309a1b-6e2d-4d03-8282-60abbbc8845b
drwxr-xr-x - root supergroup 0 2018-07-31 17:35 /tmp/checkpoint/68309a1b-6e2d-4d03-8282-60abbbc8845b/rdd-438
-rw-r--r-- 1 root supergroup 163 2018-07-31 17:35 /tmp/checkpoint/68309a1b-6e2d-4d03-8282-60abbbc8845b/rdd-438/part-00000
-rw-r--r-- 1 root supergroup 163 2018-07-31 17:35 /tmp/checkpoint/68309a1b-6e2d-4d03-8282-60abbbc8845b/rdd-438/part-00001
-rw-r--r-- 1 root supergroup 163 2018-07-31 17:35 /tmp/checkpoint/68309a1b-6e2d-4d03-8282-60abbbc8845b/rdd-438/part-00002
-rw-r--r-- 1 root supergroup 4 2018-07-31 17:35 /tmp/checkpoint/68309a1b-6e2d-4d03-8282-60abbbc8845b/rdd-438/part-00003
scala> bb.show
+----+--------+
| sex|count(1)|
+----+--------+
|null| 51|
| 0| 19|
| 1| 32|
+----+--------+
-------------------------------------------------------------------
scala> val weblogrdd=sc.textFile("hdfs://localhost:9000/spark/log/web.log")
weblogrdd: org.apache.spark.rdd.RDD[String] = hdfs://localhost:9000/spark/log/web.log MapPartitionsRDD[1] at textFile at <console>:24
scala> sc.setCheckpointDir("/tmp/checkpoint4")
[root@host ~]# hdfs dfs -ls -R /tmp/checkpoint4
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/root/hadoop/hadoop-2.7.4/share/hadoop/common/lib/slf4j-log4j12-1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/root/hive/apache-hive-2.1.1/lib/log4j-slf4j-impl-2.4.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
drwxr-xr-x - root supergroup 0 2018-08-01 13:34 /tmp/checkpoint4/c6f50081-6c31-4a5c-a1d8-afe19dcef98c
scala> weblogrdd.checkpoint
[root@host ~]# hdfs dfs -ls -R /tmp/checkpoint4
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/root/hadoop/hadoop-2.7.4/share/hadoop/common/lib/slf4j-log4j12-1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/root/hive/apache-hive-2.1.1/lib/log4j-slf4j-impl-2.4.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
drwxr-xr-x - root supergroup 0 2018-08-01 13:34 /tmp/checkpoint4/c6f50081-6c31-4a5c-a1d8-afe19dcef98c
scala> weblogrdd.count
res2: Long = 26
[root@host ~]# hdfs dfs -ls -R /tmp/checkpoint4
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/root/hadoop/hadoop-2.7.4/share/hadoop/common/lib/slf4j-log4j12-1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/root/hive/apache-hive-2.1.1/lib/log4j-slf4j-impl-2.4.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
drwxr-xr-x - root supergroup 0 2018-08-01 13:35 /tmp/checkpoint4/c6f50081-6c31-4a5c-a1d8-afe19dcef98c
drwxr-xr-x - root supergroup 0 2018-08-01 13:35 /tmp/checkpoint4/c6f50081-6c31-4a5c-a1d8-afe19dcef98c/rdd-1
-rw-r--r-- 1 root supergroup 464 2018-08-01 13:35 /tmp/checkpoint4/c6f50081-6c31-4a5c-a1d8-afe19dcef98c/rdd-1/part-00000
-rw-r--r-- 1 root supergroup 457 2018-08-01 13:35 /tmp/checkpoint4/c6f50081-6c31-4a5c-a1d8-afe19dcef98c/rdd-1/part-00001
RDD中的cache() persist() checkpoint()的更多相关文章
- 大数据学习day21-----spark04------1. 广播变量 2. RDD中的cache 3.RDD的checkpoint方法 4. 计算学科最受欢迎老师TopN
1. 广播变量 1.1 补充知识(来源:https://blog.csdn.net/huashetianzu/article/details/7821674) 之所以存在reduce side jo ...
- Spark(七)【RDD的持久化Cache和CheckPoint】
RDD的持久化 1. RDD Cache缓存 RDD通过Cache或者Persist方法将前面的计算结果缓存,默认情况下会把数据以缓存在JVM的堆内存中.但是并不是这两个方法被调用时立即缓存,而是 ...
- Checkpoint & cache & persist
checkpoint checkpoint(检查点)是Spark为了避免长链路,大计算量的Rdd不可用时,需要长时间恢复而引入的.主要就是将通过大量计算而获得的这类Rdd的数据直接持久化到外部可靠的存 ...
- RDD的cache 与 checkpoint 的区别
问题:cache 与 checkpoint 的区别? 关于这个问题,Tathagata Das 有一段回答: There is a significant difference between cac ...
- spark中的cache和persist的区别
在使用中一直知其然不知其所以然的地使用RDD.cache(),系统的学习之后发现还有一个与cache功能类似看起来冗余的persist 点进去一探究竟之后发现cache()是persist()的特例, ...
- Spark cache、checkpoint机制笔记
Spark学习笔记总结 03. Spark cache和checkpoint机制 1. RDD cache缓存 当持久化某个RDD后,每一个节点都将把计算的分片结果保存在内存中,并在对此RDD或衍生出 ...
- Spark学习笔记之RDD中的Transformation和Action函数
总算可以开始写第一篇技术博客了,就从学习Spark开始吧.之前阅读了很多关于Spark的文章,对Spark的工作机制及编程模型有了一定了解,下面把Spark中对RDD的常用操作函数做一下总结,以pys ...
- Linux内存中的Cache真的能被回收么?
在Linux系统中,我们经常用free命令来查看系统内存的使用状态.在一个RHEL6的系统上,free命令的显示内容大概是这样一个状态: [root@tencent64 ~]# free ...
- 在Spring中使用cache(EhCache的对象缓存和页面缓存)
Spring框架从version3.1开始支持cache,并在version4.1版本中对cache功能进行了增强. spring cache 的关键原理就是 spring AOP,通过 spring ...
随机推荐
- DataGridView之DataError
解决思路一: private void dgvChargeList_DataError(object sender, DataGridViewDataErrorEventArgs e) { bool ...
- Elasticsearch 5.2.x 使用 Head 插件连接不上集群
如果访问elasticsearch出现跨域的问题,如下: 修改elasticsearch.yml文件 vim $ES_HOME$/config/elasticsearch.yml # 增加如下字段 h ...
- virtualBox NAT模式,设置虚拟机可上网,宿主机可访问虚拟机的方法
环境描述: 宿主机:windows Server 2008 64bit,IPV4地址,有网络. 宿主机上的主要软件环境: virtualBox 5.0.24 virtualBox中安装了CentOS ...
- Ubuntu16.04 创建桌面快捷方式
一.基本概念 Linux 系统中的Desktop Entry 文件以desktop为后缀名.Desktop Entry 文件是 Linux 桌面系统中用于描述程序启动配置信息的文件. 进入/usr/s ...
- TweenMax 参考
http://bbs.9ria.com/thread-214959-1-1.html TweenMax 可能是很多人都用的,包括我 但 是最近发现大量的运用就总会产生这样或那样的"怪事&qu ...
- 云中树莓派(4):利用声音传感器控制Led灯
云中树莓派(1):环境准备 云中树莓派(2):将传感器数据上传到AWS IoT 并利用Kibana进行展示 云中树莓派(3):通过 AWS IoT 控制树莓派上的Led 云中树莓派(4):利用声音传感 ...
- linux上安装telnet服务
[LINUX] 使用yum 安装.开启 telnet 服务 pasting 一.安装telnet 1.检测telnet-server的rpm包是否安装 [root@localhost ~]# rpm ...
- [UE4]自定义结构体、类、数据表
自定义数据表: #pragma once #include "CoreMinimal.h" #include "Engine/UserDefinedStruct.h&qu ...
- [UE4]最简单的虚幻4网络游戏,使用虚幻4内置服务器
一.设置游戏窗口合适的大小 二.在新窗口中运行游戏.玩家数量改成大于1. 三.运行游戏就会打开多个窗口 在打包完成的游戏中进行网络游戏: 一.虚幻4打包好的文件是放在WindowsNoEditor ...
- React 懒加载组件
//组件第一次初始化的时候加载. import React, {PropTypes} from 'react'; //import AppComposer from './views/App/AppC ...