spark streaming源码分析1 StreamingContext
来源:互联网 发布:linux 修改目录结构 编辑:程序博客网 时间:2024/05/28 05:16
博客地址: http://blog.csdn.net/yueqian_zhu/
首先看一个最简单的例子,了解大致的样子:
object NetworkWordCount { def main(args: Array[String]) { if (args.length < 2) { System.err.println("Usage: NetworkWordCount <hostname> <port>") System.exit(1) } StreamingExamples.setStreamingLogLevels() // Create the context with a 1 second batch size val sparkConf = new SparkConf().setAppName("NetworkWordCount") val ssc = new StreamingContext(sparkConf, Seconds(1)) // Create a socket stream on target ip:port and count the // words in input stream of \n delimited text (eg. generated by 'nc') // Note that no duplication in storage level only for running locally. // Replication necessary in distributed scenario for fault tolerance. val lines = ssc.socketTextStream(args(0), args(1).toInt, StorageLevel.MEMORY_AND_DISK_SER) val words = lines.flatMap(_.split(" ")) val wordCounts = words.map(x => (x, 1)).reduceByKey(_ + _) wordCounts.print() ssc.start() ssc.awaitTermination() }}本小节主要介绍StreamingContext的构造
class StreamingContext private[streaming] ( sc_ : SparkContext, cp_ : Checkpoint, batchDur_ : Duration )
一、API:
1、cp_为null
def this(sparkContext: SparkContext, batchDuration: Duration)2、方法内部也是通过conf自动创建一个sparkContext,cp_为null
def this(conf: SparkConf, batchDuration: Duration)3、conf由默认的和参数部分组合而成,cp_为nulldef this( master: String, appName: String, batchDuration: Duration, sparkHome: String = null, jars: Seq[String] = Nil, environment: Map[String, String] = Map())4、从path目录下读取checkpoint的信息来重建streamingContext,也就不需要sparkContext和Duration参数def this(path: String, hadoopConf: Configuration)def this(path: String)//hadoopConf使用默认的hadoop配置文件自动构造5、使用存在的sparkContext和checkpoint路径来构造def this(path: String, sparkContext: SparkContext)6、需要注意的是,streamingContext对象内部有一个getOrCreate方法,指明如果在checkpointPath路径下读取不到,则调用creatingFunc创建新的streamingContextdef getOrCreate( checkpointPath: String, creatingFunc: () => StreamingContext, hadoopConf: Configuration = new Configuration(), createOnError: Boolean = false ): StreamingContext二、StreamingContext主要的构造逻辑(checkpoint暂不讨论)1、构造一个graph: DStreamGraph
作用于DStream上的operation分成两类 1. Transformation,2. Output 表示将输出结果。DStreamGraph 有输入就要有输出,如果没有输出,则前面所做的所有动作全部没有意义,那么如何将这些输入和输出绑定起来呢?这个问题的解决就依赖于DStreamGraph,DStreamGraph记录输入的Stream和输出的Stream。
2、构造一个JobScheduler
JobScheduler内部会构造一个jobGenerator,它用于按我们设定的批处理间隔产生job3、状态设置为INITIALIZED下一节介绍上面例子中的operation部分
1 0
- spark streaming源码分析1 StreamingContext
- spark streaming源码分析1 StreamingContext
- Spark Streaming之一:StreamingContext解析
- 5.Spark Streaming:StreamingContext详解
- Spark Streaming源码分析
- spark-streaming源码分析
- [Spark]Spark Streaming 指南二 初始化StreamingContext
- Spark定制班第25课:Spark Streaming的StreamingContext启动及JobScheduler启动源码图解
- 第25课:spark streaming的streamingContext启动及Jobschedule启动源码图解
- 第25课:Spark Streaming的StreamingContext启动及JobScheduler启动源码图解
- 图解StreamingContext、DStream、Receiver 第三讲spark streaming
- Spark Streaming源码初探 (1)
- spark streaming源码分析5 checkpoint
- Spark源码系列(八)Spark Streaming实例分析
- Spark源码系列(八)Spark Streaming实例分析
- Spark学习笔记(24)StreamingContext及JobScheduler源码图解
- Spark Streaming源码解读
- Spark Streaming源码简介
- MyEclipse常用快捷键(逐步更新)
- AT查看/设置 simcard 本身号码
- java 静态方法和实例方法的区别
- Parallels desktop调整虚拟硬盘大小失败怎么办
- Hi3516C工作记录
- spark streaming源码分析1 StreamingContext
- 【HTML】-案例-有序列表和无序列表
- PAT(甲级)1102
- 【Unity3D游戏开发学习笔记】(三)移山倒海—Terrain的建造
- PAT(甲级)1103
- 三步完成ssh免密码登录
- 18.Android 颜色工具类ColorUtil
- java判断字符串是否为空的方法总结
- 梯度下降法的简单理解