sparkstreaming+socket workCount 小案例
Consumer代码
import org.apache.spark.SparkConf
import org.apache.spark.streaming.StreamingContext
import org.apache.spark.streaming.Seconds
import org.apache.spark.storage.StorageLevel
object NetWorkStream {
def main(args: Array[String]): Unit = {
//创建sparkConf对象
var conf=new SparkConf().setMaster("spark://192.168.177.120:7077").setAppName("netWorkStream");
//创建streamingContext:是所有数据流的一个主入口
//Seconds(1)代表每一秒,批量执行一次结果
var ssc=new StreamingContext(conf,Seconds());
//从192.168.99.143接受到输入数据
var lines= ssc.socketTextStream("192.168.99.143", );
//计算出传入单词的个数
var words=lines.flatMap { line => line.split(" ")}
var wordCount= words.map { w => (w,) }.reduceByKey(_+_);
//打印结果
wordCount.print();
ssc.start();//启动进程
ssc.awaitTermination();//等待计算终止
}
nc -lk
zhang xing sheng zhang
// :: INFO scheduler.TaskSetManager: Finished task 0.0 in stage 128.0 (TID ) in ms on 192.168.177.120 (/)
// :: INFO scheduler.TaskSchedulerImpl: Removed TaskSet 128.0, whose tasks have all completed, from pool
// :: INFO scheduler.DAGScheduler: ResultStage (print at NetWorkStream.scala:) finished in 0.031 s
// :: INFO scheduler.DAGScheduler: Job finished: print at NetWorkStream.scala:, took 0.080836 s
// :: INFO spark.SparkContext: Starting job: print at NetWorkStream.scala:
// :: INFO scheduler.DAGScheduler: Got job (print at NetWorkStream.scala:) with output partitions
// :: INFO scheduler.DAGScheduler: Final stage: ResultStage (print at NetWorkStream.scala:)
// :: INFO scheduler.DAGScheduler: Parents of final stage: List(ShuffleMapStage )
// :: INFO scheduler.DAGScheduler: Missing parents: List()
// :: INFO scheduler.DAGScheduler: Submitting ResultStage (ShuffledRDD[] at reduceByKey at NetWorkStream.scala:), which has no missing parents
// :: INFO memory.MemoryStore: Block broadcast_67 stored as values in memory (estimated size 2.8 KB, free 366.2 MB)
// :: INFO memory.MemoryStore: Block broadcast_67_piece0 stored as bytes in memory (estimated size 1711.0 B, free 366.2 MB)
// :: INFO storage.BlockManagerInfo: Added broadcast_67_piece0 in memory on 192.168.177.120: (size: 1711.0 B, free: 366.3 MB)
// :: INFO spark.SparkContext: Created broadcast from broadcast at DAGScheduler.scala:
// :: INFO scheduler.DAGScheduler: Submitting missing tasks from ResultStage (ShuffledRDD[] at reduceByKey at NetWorkStream.scala:)
// :: INFO scheduler.TaskSchedulerImpl: Adding task set 130.0 with tasks
// :: INFO scheduler.TaskSetManager: Starting task 0.0 in stage 130.0 (TID , 192.168.177.120, partition , NODE_LOCAL, bytes)
// :: INFO cluster.CoarseGrainedSchedulerBackend$DriverEndpoint: Launching task on executor id: hostname: 192.168.177.120.
// :: INFO storage.BlockManagerInfo: Added broadcast_67_piece0 in memory on 192.168.177.120: (size: 1711.0 B, free: 366.3 MB)
// :: INFO scheduler.TaskSetManager: Finished task 0.0 in stage 130.0 (TID ) in ms on 192.168.177.120 (/)
// :: INFO scheduler.TaskSchedulerImpl: Removed TaskSet 130.0, whose tasks have all completed, from pool
// :: INFO scheduler.DAGScheduler: ResultStage (print at NetWorkStream.scala:) finished in 0.014 s
// :: INFO scheduler.DAGScheduler: Job finished: print at NetWorkStream.scala:, took 0.022658 s
-------------------------------------------
Time: ms
-------------------------------------------
(xing,)
(zhang,)
(sheng,)
- 定义上下文之后,你应该做下面事情
After a context is defined, you have to do the following.- 根据创建DStream定义输入数据源
- Define the input sources by creating input DStreams.
- 定义计算方式DStream转换和输出
Define the streaming computations by applying transformation and output operations to DStreams.- 使用streamingContext.start()启动接受数据的进程
Start receiving data and processing it using streamingContext.start().- 等待进程结束
Wait for the processing to be stopped (manually or due to any error) using streamingContext.awaitTermination().- 手动关闭进程
The processing can be manually stopped using streamingContext.stop().
- 一旦一个上下文启动,不能在这个上下文中设置新计算或者添加
Once a context has been started, no new streaming computations can be set up or added to it.- 一旦一个上下文停止,就不能在重启
Once a context has been stopped, it cannot be restarted.- 在同一时间一个jvm只能有一个StreamingContext 在活动
Only one StreamingContext can be active in a JVM at the same time.//ssc.stop(false)- 在StreamingContext 上使用stop函数,同事也会停止sparkContext,仅仅停止StreamingContext,在调用stopSparkContext设置参数为false
stop() on StreamingContext also stops the SparkContext. To stop only the StreamingContext, set the optional parameter of stop() called stopSparkContext to false.- 一个SparkContext 可以创建多个streamingContext和重用,只要在上一个StreamingContext停止前创建下一个StreamingContext
A SparkContext can be re-used to create multiple StreamingContexts, as long as the previous StreamingContext is stopped (without stopping the SparkContext) before the next StreamingContext is created.
sparkstreaming+socket workCount 小案例的更多相关文章
- C# Socket通信 小案例
本文将编写2个控制台应用程序,一个是服务器端(server),一个是客户端(client), 通过server的监听,有新的client连接后,接收client发出的信息. server代码如下: u ...
- MVC 小案例 -- 信息管理
前几次更新博客都是每次周日晚上到周一,这次是周一晚上开始写,肯定也是有原因的!那就是我的 Tomact 忽然报错,无法启动,错误信息如下!同时我的 win10 也崩了,重启之后连 WIFI 的标志也不 ...
- Python:通过一个小案例深入理解IO多路复用
通过一个小案例深入理解IO多路复用 假如我们现在有这样一个普通的需求,写一个简单的爬虫来爬取校花网的主页 import requests import time start = time.time() ...
- 机械表小案例之transform的应用
这个小案例主要是对transform的应用. 时钟的3个表针分别是3个png图片,通过setInterval来让图片转动.时,分,秒的转动角度分别是30,6,6度. 首先,通过new Date函数获取 ...
- shell讲解-小案例
shell讲解-小案例 一.文件拷贝输出检查 下面测试文件拷贝是否正常,如果cp命令并没有拷贝文件myfile到myfile.bak,则打印错误信息.注意错误信息中basename $0打印脚本名.如 ...
- [jQuery学习系列六]6-jQuery实际操作小案例
前言最后在这里po上jQuery的几个小案例. Jquery例子1_占位符使用需求: 点击第一个按钮后 自动去check 后面是否有按钮没有选中, 如有则提示错误消息. <html> &l ...
- 02SpringMvc_springmvc快速入门小案例(XML版本)
这篇文章中,我们要写一个入门案例,去整体了解整个SpringMVC. 先给出整个项目的结构图:
- React.js入门小案例
<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <title&g ...
- SqlDependency缓存数据库表小案例
SqlDependency的简介: SqlDependency是outputcache网页缓存的一个参数,它的作用是指定缓存失效的数据库依赖项,可以具体到数据库和表. SqlDependency能解决 ...
随机推荐
- 后门构建工具Backdoor Factory
后门构建工具Backdoor Factory 在渗透测试中,后门程序帮助渗透测试人员在目标机器上执行各种预期的操作.例如,它可以建立从目标主机到攻击机的网络连接,方便渗透测试人员控制目标主机.Ka ...
- Sum of bit differences among all pairs
This article was found from Geeksforgeeks.org. Click here to see the original article. Given an inte ...
- 博客 | 基于Travis CI实现Hexo在Github和Coding的同步自动化部署
文章目录 完成Hexo主题安装和配置 基于Travis CI实现同步部署 参考内容 相关链接 待补充 完成Hexo主题安装和配置 如果您还没有安装Hexo环境,请参考Hexo文档安装,也给出这样两篇博 ...
- mysql语法语句
将一个字段中的timestamp修改成可视化时间 update table set f1 = IF( LOCATE('-',f1)>0, f1, IFNULL(FROM_UNIXTIME(f1/ ...
- 用字符串连接SQL语句并用EXEC执行时,出现名称 '‘不是有效的标识符
原文:用字符串连接SQL语句并用EXEC执行时,出现名称 ''不是有效的标识符 用字符串连接SQL语句并用EXEC执行时,出现名称 '这里是字符串连接的一条SQL语句‘不是有效的标识符 才发现,在写e ...
- [置顶]
cAdvisor、InfluxDB、Grafana搭建Docker1.12性能监控平台
通过cadvisor+influxdb+grafana三者有机结合,打造跨主机容器监控. 优点 1.跨主机监控,可扩展 2.容器自发现 3.历史数据长期保存 4.自定义配置程度高 缺点 1.不能自动隐 ...
- python 文件操作的注意事项
我们经常用python读取文件信息,这里有些注意事项 with open('test.txt', 'r') as f: print 'f.read', f.read() with open('test ...
- 项目笔记:导出Excel功能设置导出数据样式
/** * 导出-新导出 * * @return * @throws IOException */ @OperateLogAnn(type = OperateEnum.EXPORT, hibInter ...
- ElasticSearch 相关性
1.相关性 ElasticSearch检索结果是按照相关性倒序排列的,相关性是什么,相关性又是如何计算的?每个文档都有相关性评分,用一个正浮点数字段 _score 来表示 . _score 的评分越高 ...
- IntelliJ IDEA 快捷键整理-from imooc
IntelliJ IDEA 快捷键整理-from imooc 学习了:https://www.imooc.com/learn/9241, main2, 100.for 3, new Date().so ...