宝塔服务器面板,一键全能部署及管理,送你10850元礼包,点我领取

本篇文章为大家展示了怎么解析spark的宽窄依赖和持久化,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。

一.持久化官网

1.官网位置截图

怎么解析spark的宽窄依赖和持久化-冯金伟博客园

2.cache 源码

cache底层调用的是persisit  ,默认参数是StorageLevel.MEMORY_ONLY
cache 用完最好手动干掉

怎么解析spark的宽窄依赖和持久化-冯金伟博客园

3.StorageLevel源码

怎么解析spark的宽窄依赖和持久化-冯金伟博客园

4.StorageLevel 解释

是否使用磁盘
是否使用内存
不管
反序列化
副本

5.persisit 可以传的参数

怎么解析spark的宽窄依赖和持久化-冯金伟博客园

6.官网:怎么选择缓存?

怎么解析spark的宽窄依赖和持久化-冯金伟博客园

7.上图解释

选择默认第一种MEMORY_ONLY 
内存不够选怎序列化
磁盘最好别选择
不要用这个副本形式耗内存
缓存选择:
Spark’s storage levels are meant to provide different trade-offs (权衡)between memory usage and CPU efficiency.We recommend going through the following process to select one: 选择方式
    优先级从上到下
    优先选择第一个MEMORY_ONLY ,内存实在不够就序列化
    If your RDDs fit comfortably with the default storage level (MEMORY_ONLY), leave them that way 默认可以搞定就用默认的. This is the most CPU-efficient option, allowing operations on the RDDs to run as fast as possible.
    不要选择java的序列化
    If not, try using MEMORY_ONLY_SER and selecting a fast serialization library to make the objects much more space-efficient 空间很好, but still reasonably fast to access. (Java and Scala)
    Don’t spill to disk 不要放到磁盘 unless the functions that computed your datasets are expensive, or they filter a large amount of the data. Otherwise, recomputing a partition may be as fast as reading it from disk.

二.宽窄依赖,血缘关系

1.总结

宽依赖用shufer
宽窄依赖容错程度不一样
一个shuffer产生两个stage,两个产生三个stage等等
Lineage 血缘关系  用于容错很多都是记录的
textfile =》 xx => yy
描述的是一个RDD如何从父RDD过来的
RDD作用一个函数就是对RDD里面的分区作用一个函数
丢失了根据父RDD重新算一下
dependence
    宽依赖:一个父RDD的partition至多被子RDD的某个partition使用一次   没shuffer
    pipline     丢一个就直接拿出来计算就可以
    窄依赖:一个父RDD的parttiton会被子RDD的partitio使用多次    有shuffer
    宽依赖挂掉了要从父RDD全部计算
    有的时候解决数据倾斜需要shuffer
    他们容错程度不一样的
    有shuffer就会生成stage
总结:老子被儿子用几次,多个孩子(宽)或单个孩子(窄)

2.driver

driver  就是main方法 中创建sparkcontext
action 产生job  ,shuffer 产生stage  ,stage 里是task