您的位置:首页 > 其它

spark streaming -- (视频笔记)

2016-01-02 22:26 309 查看
1、spark: one stack to rule them all

一个堆栈解决所有的计算问题

2、大数据第一个问题,如何存储,HDFS已经完美解决了。

3、资源管理就是yarn,mesource

4、大数据如何计算。MR将被Spark取代。

batch计算

实时流计算 spark streaming

交互式查询 spark sql,impala,tez

---------------------------------------------------

spark vs storm vs S4

1、storm 单条时间为 200ms

2、spark streaming batch 时间最小 500ms

3、spark streaming的吞吐量远大于storm更远大于S4

------------------------------------------------------------------

what is spark streaming

为大规模的可伸缩的实时的流处理框架

可以再数百个节点上运行

可以秒级别处理数据

便于批量数据操作

api简洁

数据来源有很多,kafka、flume、zeroMQ.....

--------------------------------------------

A quick example

val ssc = new streamingcontext(sparkconf,seconds(1))

val lines = ssc.sockettextstream(ip,port)

val words = lines.flatMap(_.split(" "))

val pairs = words.map=>map(word,1)

val wordcounts = pairs.reducebykey(_+_)

wordcounts.print();

ssc.start()

ssc.awaittermations();

-----------------------------------------------------

spark streaming data flow

input data stream ==> spark streaming ==> batches of input data ==>spark engine(spark core) ==> batches of processed data

------------------------------------------------------

discretized stream processing

获取线上的流数据(一秒或者两秒。。。。。),将每秒的数据合并为block,后续的处理都是操作的block。

-------------------------------------

operations on dstream

lines

DStream ----- RDD@time1 -------- RDD@time2 -------- RDD@time3

words

DStream----- words@time1 -------- words@time2 -------- words@time3

三个DStream,

--------------------------------

spark 是如何容错的(fault-tolerance)

spark流数据,默认有一份备份在别的机器的内存中

spark流数据,每隔一段时间会进行checkpoint

hdfs默认做一次checkpoint要一个小时。

--------------------------

static operations && window operations

window操作

假设要统计近10分钟的数据,时间分片是1秒,window操作会每秒都将近十分钟的数据进行运算

造成很多重复的运算,因此要进行优化, 就需要去掉旧的,加上新的。

hashTags.reduceByKeyAndWindow(_+_,_+_,Minutes(1),...)

-------------------------------------------

优化

batch size 大小:batch size的处理时间必须大于batch时间(消费者模式),极容易发生阻塞,如果发生阻塞,1增加并行度,2增加日志(log4j或者更好用的streaminglistening)

内存优化:默认两份;默认会序列化掉后存储在内存,建议直接去掉序列化,降低cpu,如果非要用序列化可以选用Kryo或protobuf;及时清理缓存,必须设置 spark cleaner.ttl,设置spark.streaming.unpersis,系统会为你做一些东西;java GC选用cms(暂停时间段,但吞吐率不高,并且会引起内存碎片)

-XX:CMSFullGcsBeforeCormpaction

-------------------------------------------------------
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: