spark streaming实时流笔记六
spark streaming 入门
概述
Spark Streaming is an extension of the core Spark API that enables scalable,
high-throughput, (高吞吐量)
fault-tolerant (容错)
stream processing of live data streams.
Spark Streaming 的定义:
将不同的数据源的数据经过Spark Streaming处理之后将结果输出到外部文件系统
特点: 低延时
能从错误中高效的恢复:容错
能够运行在成百上千的节点
能够将批处理、机器学习、图计算等自框架和Spark Streaming综合起来使用
Spark streaming 是否需要独立安装?
One stack to rule them all :一栈式解决
应用场景
金融欺诈
集成Spark生态系统的使用
发展史
从词频统计功能着手入门
GitHub
https://github.com/apache/spark
spark-submit执行(生产上的)
先命令行:nc -lk 9999
./spark-submit --master local[2]
–class org.apache.spark.examples.streaming.NetworkWordCount
–name NetworkWordCount
/home/hadoop/app/spark-2.2.0-bin-2.6.0-cdh5.7.0/examples/jars/spark-examples_2.11-2.2.0.jar hadoop000 9999
spark-shell执行提交(测试)
./spark-shell --master local[2]
import org.apache.spark.streaming.{Seconds, StreamingContext}
val ssc = new StreamingContext(sc, Seconds(1))
val lines = ssc.socketTextStream("hadoop000",9999)
val words = lines.flatMap(_.split(" "))
val wordCounts = words.map(x => (x, 1)).reduceByKey(_ + _)
wordCounts.print()
ssc.start()
ssc.awaitTermination()
工作原理
粗粒度:Spark Streaming接收到实时数据流,把数据按照指定的时间段切成一片片小的数据块,然后把小的数据块传给Spark Engine处理
细粒度: