一、RDD主要特点及在源码的体现
1.1 RDD主要特点:
(1) 被创建的RDD包含一系列的分区,这是它可以并行处理的基础;
(2) RDD之间一系列的依赖;
(3) 运算每一个分区的函数;
(4) Partitioner=> K-V RDDs (RDD是基于哈希分区);
(5) 尽量选择好的存储位置来运算每一个分区。
1.2 RDD特点主要特点在源码的体现
(1)特点一:
final def partitions: Array[Partition] = {
checkpointRDD.map(_.partitions).getOrElse {
if (partitions_ == null) {
partitions_ = getPartitions
partitions_.zipWithIndex.foreach { case (partition, index) =>
require(partition.index == index,
s"partitions($index).partition == ${partition.index}, but it should equal $index")
}
}
partitions_
}
}
(2) 特点二:
/**
* Implemented by subclasses to return how this RDD depends on parent RDDs. This method will only
* be called once, so it is safe to implement a time-consuming computation in it.
*/
protected def getDependencies: Seq[Dependency[_]] = deps
(3) 特点三:
/**
* :: DeveloperApi ::
* Implemented by subclasses to compute a given partition.
*/
@DeveloperApi
def compute(split: Partition, context: TaskContext): Iterator[T]
(4) 特点四:
protected def getPartitions: Array[Partition]
(5)特点五
protected def getPreferredLocations(split: Partition): Seq[String] = Nil
二、Spark standalone
三、SparkContext与SparkConf的作用
3.1 SparkContext 的作用
(1) 连接Spark的主要入口点;
(2) 用于创建RDD和共享变量(广播变量和累加器)
(3) 每一个JVM只可有一个正在运行的SparkContext,在启动其它一个新的SparkContext之前,并且每次使用完SparkContext之后,都要关掉。因为运行SparkContext是会消耗资源的!
3.2 SparkConf 作用
(1)设置不同的Spark应用程序的各种参数,以键值对的形式;
(2)从所有“spark.*”和Java文件系统中加载属性值(这些属性值优于系统属性);
(3)单元测试=>new SparkConf(false) 这个方法跳过加载外部的设置和获得相同的配置而不用系统属性是啥。
(4) 在这个类的方法都支持链式编程,
new SparkConf().setMaster("local").setAppName("My app")`.
(5) SparkConf 对象一旦被传递到Spark中,它被复制后将不会被修改,Spark也不支持在运行过程中更改配置。