1.广播变量是什么
普通变量每个任务都会得到这些变量的一份副本,广播变量是只读变量,打破了这一限制
2.使用
调用要使用.value来调用
object spark03 {
def main(args: Array[String]): Unit = {
val conf = new SparkConf();
conf.setAppName("broadcast")
conf.setMaster("local")
val list=List("hello hadoop")
val context: SparkContext = new SparkContext(conf)
val value: RDD[String] = context.textFile("D:\BigData\spark\filterWC\src\main\data\word")
val broadcast: Broadcast[List[String]] = context.broadcast(list)
value.filter(x=>broadcast.value.contains(x)).foreach(println)
}
}
3.累加器
将工作节点中的值居合道驱动器中,常见用途是在调试时对作业执行过程中的事件进行计数。
4.使用
longAccumulator或doubleAccumulator来调用
object spark04 {
def main(args: Array[String]): Unit = {
val conf = new SparkConf()
conf.setAppName("accumulator")
conf.setMaster("local")
val context = new SparkContext(conf)
val accumulator: LongAccumulator = context.longAccumulator
context.textFile("D:\BigData\spark\filterWC\src\main\data\word").foreach{
x=>{accumulator.add(1)}
}
println(accumulator.value)
}
}
5.Master的高可用



