Spark-Dependency
1、Spark中採用依赖关系(Dependency)表示rdd之间的生成关系。Spark可利用Dependency计算出失效的RDD。在每一个RDD中都存在一个依赖关系的列表
private var dependencies_ : Seq[Dependency[_]] = null
用以记录各rdd中各partition的parent partition。
2、Spark中存在两类Dependency:
1)NarrowDependency表示的是一个父partition仅相应于一个子partition。这种依赖关系是不须要shuffle的。在这类依赖中。能够依据getParents方法获取某个partition的父partitions:
/**
* :: DeveloperApi ::
* Base class for dependencies where each partition of the parent RDD is used by at most one
* partition of the child RDD. Narrow dependencies allow for pipelined execution.
*/
@DeveloperApi
abstract class NarrowDependency[T](rdd: RDD[T]) extends Dependency(rdd) {
/**
* 唯一的接口。获得该partition的全部parent partition
* Get the parent partitions for a child partition.
* @param partitionId a partition of the child RDD
* @return the partitions of the parent RDD that the child partition depends upon
*/
def getParents(partitionId: Int): Seq[Int]
}
这类又可分为:
a、OneToOneDependency:表示一一相应的依赖关系,因为在这样的依赖中父partition与子partition Id是一致的,所以getParents直接原样返回。相应的转换操作有map和filter
class OneToOneDependency[T](rdd: RDD[T]) extends NarrowDependency[T](rdd) {
/**
* 事实上partitionId就是partition在RDD中的序号, 所以假设是一一相应, 那么parent和child中的partition的序号应该是一样的
*/
override def getParents(partitionId: Int) = List(partitionId)//原样返回
}
b、PruneDependency(org.apache.spark.rdd.PartitionPruningRDDPartition):未详
/**
* Represents a dependency between the PartitionPruningRDD and its parent. In this
* case, the child RDD contains a subset of partitions of the parents'.
*/
private[spark] class PruneDependency[T](rdd: RDD[T], @transient partitionFilterFunc: Int => Boolean)
extends NarrowDependency[T](rdd) { @transient
val partitions: Array[Partition] = rdd.partitions
.filter(s => partitionFilterFunc(s.index)).zipWithIndex
.map { case(split, idx) => new PartitionPruningRDDPartition(idx, split) : Partition } override def getParents(partitionId: Int) = {
List(partitions(partitionId).asInstanceOf[PartitionPruningRDDPartition].parentSplit.index)
}
}
c、RangeDependency:这样的是父rdd的连续多个partitions相应子rdd中的连续多个partitions。相应的转换有union
/**Union
* :: DeveloperApi ::
* Represents a one-to-one dependency between ranges of partitions in the parent and child RDDs.
* @param rdd the parent RDD
* @param inStart the start of the range in the parent RDD parent RDD中区间的起始点
* @param outStart the start of the range in the child RDD child RDD中区间的起始点
* @param length the length of the range
*/
@DeveloperApi
class RangeDependency[T](rdd: RDD[T], inStart: Int, outStart: Int, length: Int)
extends NarrowDependency[T](rdd) { override def getParents(partitionId: Int) = {
if (partitionId >= outStart && partitionId < outStart + length) {//推断partitionId的合理性,必须在child RDD的合理partition范围
List(partitionId - outStart + inStart)//算出parent RDD中相应的partition id
} else {
Nil
}
}
}
2)WideDependency:这样的依赖是指一个父partition能够相应子rdd中多个partitions。因为须要对父partition进行划分,故须要用到shuffle,而shuffle通常是採用键值对的。
这里为每一个shuffle分配了一个全局唯一的shuffleId。
为了进行shuffle。须要指定怎样进行shuffle,这相应于參数partitioner;因为shuffle是须要网络传输的。故须要进行序列化Serializer。在宽依赖中并无法获得partition相应的parent partitions?
/**
* :: DeveloperApi ::
* Represents a dependency on the output of a shuffle stage.
* @param rdd the parent RDD
* @param partitioner partitioner used to partition the shuffle output
* @param serializer [[org.apache.spark.serializer.Serializer Serializer]] to use. If set to null,
* the default serializer, as specified by `spark.serializer` config option, will
* be used.
*/
@DeveloperApi
class ShuffleDependency[K, V](
@transient rdd: RDD[_ <: Product2[K, V]],
val partitioner: Partitioner,//须要给出partitioner, 指示怎样完毕shuffle
val serializer: Serializer = null)//shuffle不象map能够在local进行, 往往须要网络传输或存储, 所以须要serializerClass
extends Dependency(rdd.asInstanceOf[RDD[Product2[K, V]]]) { val shuffleId: Int = rdd.context.newShuffleId()//每一个shuffle须要分配一个全局的id, context.newShuffleId()的实现就是把全局id累加 rdd.sparkContext.cleaner.foreach(_.registerShuffleForCleanup(this))
}
Spark-Dependency的更多相关文章
- Spark快速入门 - Spark 1.6.0
Spark快速入门 - Spark 1.6.0 转载请注明出处:http://www.cnblogs.com/BYRans/ 快速入门(Quick Start) 本文简单介绍了Spark的使用方式.首 ...
- 在 Azure HDInsight 中安装和使用 Spark
Spark本身用Scala语言编写,运行于Java虚拟机(JVM).只要在安装了Java 6以上版本的便携式计算机或者集群上都可以运行spark.如果您想使用Python API需要安装Python解 ...
- spark mllib配置pom.xml错误 Multiple markers at this line Could not transfer artifact net.sf.opencsv:opencsv:jar:2.3 from/to central (https://repo.maven.apache.org/maven2): repo.maven.apache.org
刚刚spark mllib,在maven repository网站http://mvnrepository.com/中查询mllib后得到相关库的最新dependence为: <dependen ...
- Spark实战3:Maven_Java_HelloWorld
Spark独立开发应用( Java语言) 1 创建SimpleApp.java文件: /* SimpleApp.java */ import org.apache.spark.api.java.*; ...
- Spark RDD概念学习系列之RDD的转换(十)
RDD的转换 Spark会根据用户提交的计算逻辑中的RDD的转换和动作来生成RDD之间的依赖关系,同时这个计算链也就生成了逻辑上的DAG.接下来以“Word Count”为例,详细描述这个DAG生成的 ...
- Spark RDD概念学习系列之rdd的依赖关系彻底解密(十九)
本期内容: 1.RDD依赖关系的本质内幕 2.依赖关系下的数据流视图 3.经典的RDD依赖关系解析 4.RDD依赖关系源码内幕 1.RDD依赖关系的本质内幕 由于RDD是粗粒度的操作数据集,每个Tra ...
- Spark IDEA开发环境构建
本文档基于IEDA构建spark maven应用. date: 2016/8/1 author: wangxl 1.下载IDEA https://www.jetbrains.com/idea/ 2.安 ...
- CentOS7 安装spark集群
Spark版本 1.6.0 Scala版本 2.11.7 Zookeeper版本 3.4.7 配置虚拟机 3台虚拟机,sm,sd1,sd2 1. 关闭防火墙 systemctl stop firewa ...
- Spark 2.2.0 文档中文版 Quick Start
原地址:http://spark.apache.org/docs/latest/quick-start.html 这篇指导对使用Spark提供了一个快速的介绍.我们首先介绍API,通过spark交互式 ...
- Spark快速入门
Spark 快速入门 本教程快速介绍了Spark的使用. 首先我们介绍了通过Spark 交互式shell调用API( Python或者scala代码),然后演示如何使用Java, Scala或者P ...
随机推荐
- 【数论】【原根】【动态规划】【bitset】2017四川省赛 K.2017 Revenge
题意: 给你n(不超过200w)个数,和一个数r,问你有多少种方案,使得你取出某个子集,能够让它们的乘积 mod 2017等于r. 2017有5这个原根,可以使用离散对数(指标)的思想把乘法转化成加法 ...
- 【欧拉回路】【欧拉路径】【Fleury算法】CDOJ1634 记得小苹初见,两重心字罗衣
Fleury算法看这里 http://hihocoder.com/problemset/problem/1181 把每个点看成边,每个横纵坐标看成一个点,得到一个无向图. 如果新图中每个点的度都是偶数 ...
- Java学习笔记(10)
目前多态情况下不能访问子类特有的成员 如果需要访问子类特有的成员,那么需要进行类型强制转换,转换为子类的类型然后再进行调用 基本数据类型的转换: 小数据类型------------->大数据类型 ...
- python多线程以及同步队列(转)
转自:http://www.w3cschool.cc/python/python-multithreading.html 多线程类似于同时执行多个不同程序,多线程运行有如下优点: 使用线程可以把占据长 ...
- HDU 4576 Robot (很水的概率题)
Robot Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 102400/102400 K (Java/Others)Total Sub ...
- enum don't allocate any memory
int main() { _asm{ mov edi,edi mov edi,edi } ,Green,Yellow}; _asm{ mov edi,edi mov edi,edi } Color c ...
- tcpreplay工具使用
参考:http://www.cnblogs.com/jiayy/p/3447047.html 速率控制算法的大体思路就是,通过适当的sleep,增加包发送的时间,从而减小算出来的速率,以达到用户设 ...
- ENVI裁剪
一.basic tools-->resize data进行规则裁剪 虽然是进行图像重采样工具,但也可以用于简单快速的裁剪 1. 选中要裁剪的图像: 对话框下面选择spatial subset(构 ...
- 【Rocket MQ】RocketMQ4.2.0 和 spring boot的结合使用,实现分布式事务
RocketMQ4.2.0 和 spring boot的结合使用,实现分布式事务 参考地址:https://www.jianshu.com/p/f57de40621a0
- 永远不要去B网(Bittrex.com)
永远不要去Bittrex.com,没见过这么垃圾的服务! 注册之后基本资料就不能修改了,结果不能提现,充值却是可以充值,就跟今年初禁比特币时的垃圾火币网一样,只进不出,去他奶奶的! 随后网站提示可以高 ...