NetworkWordCount 例子工作流程详解
来源:互联网 发布:定车票的软件 编辑:程序博客网 时间:2024/06/01 08:10
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() }}
- ssc.socketTextStream(),读取数据到lines中,StreamingContext.scala中
- lines.flatMap(_.split(” “))将每一行中的单词按照空格分开成一个一个的独立单词在words里面,Dstream.scala中:flatMap产生的是FlatMappedDStream,
- words.map(x => (x, 1))将每个单词映射成(key,value)格式,前面是单词后面是1 代表该单词出现一次,Dstream.scala中:Map产生的是MappedDStream
- 接着是reduceByKey(+),该方法通过操作map()生成的(key,value)按key统计实现了相同key的value累加,PairDStreamFunctions.scala中reduceByKey产生的是shuffledDStream
- wordCounts.print(),Dstream.scala中:
在这里面调用了foreachRDD,foreachRDD返回类型是Unit,但是里面生成一个ForEachDStream是一个输出型的RDD,会注册给DstreamGraph, DstreamGraph .scala中的outputStreams
ForEachDStream.scala中:
-
-注册的代码
,
DstreamGraph .scala中outputStreams变量
,,,
6. 既然有outputStreams那么就有inputstreams通过回溯可以找到是什么时候放到DstreamGraph 中的
–
0 0
- NetworkWordCount 例子工作流程详解
- Hibernate例子和工作流程
- 详解MapReduce工作流程
- 详解MapReduce工作流程
- Struts1工作流程详解
- 编译器工作流程详解
- oozie 工作流程详解
- Makfile详解-工作流程
- 详解SpringMVC 工作流程
- 详解MapReduce工作流程
- 详解uboot1.1.6工作流程
- XMPP 协议工作流程详解
- XMPP 协议工作流程详解
- XMPP 协议工作流程详解
- Oozie工作流程定义详解
- Oozie工作流程定义详解
- Oozie工作流程定义详解
- Oozie工作流程定义详解
- Android应用性能优化之使用SparseArray替代HashMap
- PHP 获取页面URL
- 欢迎使用CSDN-markdown编辑器
- 用python计算md5,sha1,crc32
- 基于结构光的深度测距structure light coding
- NetworkWordCount 例子工作流程详解
- WordPress简单移除程序和插件更新提示
- Jmeter之Bean shell使用(一)
- Java学习笔记第十天:3_内部类
- 数据驱动编程与表驱动法(多if-else结构精简)
- Frame Up_usaco 4.4_拓扑排序
- 互联网:互联网进入下半场,这场赛怎么比?
- NOIP2011 铺地毯ACC 程序pascal加题解
- 在VsPackage中使用errorlist