付费下载
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
SparkStreaming技术介绍王新义摘要SparkStreaming示例SparkStreaming架构和原理StreamingVSstorm流式处理框架:flume+kafka+streaming示例:socketWordCount示例:JavaKafkaWordCountSparkStreaming体系结构SparkStreamingDataFLowDiscretizedStreams(DStreams)WindowOperationsInputDStreamsFileScoketQueueKafkaflumeTransformationsonDStreamsTransformationMeaningmap(func)ReturnanewDStreambypassingeachelementofthesourceDStreamthroughafunction
func.flatMap(func)Similartomap,buteachinputitemcanbemappedto0ormoreoutputitems.filter(func)ReturnanewDStreambyselectingonlytherecordsofthesourceDStreamonwhich
func
returnstrue.repartition(numPartitions)ChangesthelevelofparallelisminthisDStreambycreatingmoreorfewerpartitions.union(otherStream)ReturnanewDStreamthatcontainstheunionoftheelementsinthesourceDStreamand
otherDStream.count()ReturnanewDStreamofsingle-elementRDDsbycountingthenumberofelementsineachRDDofthesourceDStream.reduce(func)ReturnanewDStreamofsingle-elementRDDsbyaggregatingtheelementsineachRDDofthesourceDStreamusingafunction
func
(whichtakestwoargumentsandreturnsone).Thefunctionshouldbeassociativesothatitcanbecomputedinparallel.countByValue()WhencalledonaDStreamofelementsoftypeK,returnanewDStreamof(K,Long)pairswherethevalueofeachkeyisitsfrequencyineachRDDofthesourceDStream.reduceByKey(func,[numTasks])WhencalledonaDStreamof(K,V)pairs,returnanewDStreamof(K,V)pairswherethevaluesforeachkeyareaggregatedusingthegivenreducefunction.
Note:
Bydefault,thisusesSpark'sdefaultnumberofparalleltasks(2forlocalmode,andinclustermodethenumberisdeterminedbytheconfigpropertyspark.default.parallelism)todothegrouping.Youcanpassanoptional
numTasks
argumenttosetadifferentnumberoftasks.join(otherStream,[numTasks])WhencalledontwoDStreamsof(K,V)and(K,W)pairs,returnanewDStreamof(K,(V,W))pairswithallpairsofelementsforeachkey.cogroup(otherStream,[numTasks])WhencalledonDStreamof(K,V)and(K,W)pairs,returnanewDStreamof(K,Seq[V],Seq[W])tuples.transform(func)ReturnanewDStreambyapplyingaRDD-to-RDDfunctiontoeveryRDDofthesourceDStream.ThiscanbeusedtodoarbitraryRDDoperationsontheDStream.updateStateByKey(func)Returnanew"state"DStreamwherethestateforeachkeyisupdatedbyapplyingthegivenfunctiononthepreviousstateofthekeyandthenewvaluesforthekey.Thiscanbeusedtomaintainarbitrarystatedataforeachkey.Transformations(Window)TransformationMeaningwindow(windowLength,
slideInterval)ReturnanewDStreamwhichiscomputedbasedonwindowedbatchesofthesourceDStream.countByWindow(windowLength,slideInterval)Returnaslidingwindowcountofelementsinthestream.reduceByWindow(func,
windowLength,slideInterval)Returnanewsingle-elementstream,createdbyaggregatingelementsinthestreamoveraslidingintervalusing
func.Thefunctionshouldbeassociativesothatitcanbecomputedcorrectlyinparallel.reduceByKeyAndWindow(func,windowLength,
slideInterval,[numTasks])WhencalledonaDStreamof(K,V)pairs,returnsanewDStreamof(K,V)pairswherethevaluesforeachkeyareaggregatedusingthegivenreducefunction
func
overbatchesinaslidingwindow.
Note:
Bydefault,thisusesSpark'sdefaultnumberofparalleltasks(2forlocalmode,andinclustermodethenumberisdeterminedbytheconfigpropertyspark.default.parallelism)todothegrouping.Youcanpassanoptional
numTasks
argumenttosetadifferentnumberoftasks.reduceByKeyAndWindow(func,
invFunc,windowLength,
slideInterval,[numTasks])Amoreefficientversionoftheabove
reduceByKeyAndWindow()
wherethereducevalueofeachwindowiscalculatedincrementallyusingthereducevaluesofthepreviouswindow.Thisisdonebyreducingthenewdatathatentertheslidingwindow,and"inversereducing"theolddatathatleavethewindow.Anexamplewouldbethatof"adding"and"subtracting"countsofkeysasthewindowslides.However,itisapplicabletoonly"invertiblereducefunctions",thatis,thosereducefunctionswhichhaveacorresponding"inversereduce"function(takenasparameter
invFunc.Likein
reduceByKeyAndWindow,thenumberofreducetasksisconfigurablethroughanoptionalargument.countByValueAndWindow(windowLength,slideInterval,[numTasks])WhencalledonaDStreamof(K,V)pairs,returnsanewDStreamof(K,Long)pairswherethevalueofeachkeyisitsfrequencywithinaslidingwindow.Likein
reduceByKeyAndWindow,thenumberofreducetasksisconfigurablethroughanoptionalargument.OutputOperationsonDStreamsOutputOperationMeaningprint()PrintsfirsttenelementsofeverybatchofdatainaDStreamonthedriver.Thisisusefulfordevelopmentanddebugging.saveAsObjectFiles(prefix,[suffix])SavethisDStream'scontentsasa
SequenceFile
ofserializedobjects.Thefilenameateachbatchintervalisgeneratedbasedon
prefix
and
suffix:
"prefix-TIME_IN_MS[.suffix]".saveAsTextFiles(prefix,[suffix])SavethisDStream'scontentsasatextfiles.Thefilenameateachbatchintervalisgeneratedbasedon
prefix
and
suffix:
"prefix-TIME_IN_MS[.suffix]".saveAsHadoopFiles(prefix,[suffix])SavethisDStream'scontentsasaHadoopfile.Thefilenameateachbatchintervalisgeneratedbasedon
prefix
and
suffix:
"prefix-TIME_IN_MS[.suffix]".foreachRDD(func)Themostgenericoutputoperatorthatappliesafunction,
func,toeachRDDgeneratedfromthestream.ThisfunctionshouldpushthedataineachRDDtoaexternalsystem,likesavingtheRDDtofiles,orwritingitoverthenetworktoadatabase.Notethatthefunction
func
isexecutedatthedriver,andwillusuallyhaveRDDactionsinitthatwillforcethecomputationofthestreamingRDDs.OutputOperations:foreachRDDwordCounts.foreachRDD(newFunction<JavaPairRDD<String,Integer>,Void>(){@Override
publicVoidcall(JavaPairRDD<String,Integer>arg0)throwsException{arg0.saveAsTextFile("/user/root/stream/kafka"+System.currentTimeMillis());//List<Tuple2<String,Integer>>list=arg0.collect();
returnnull;
}
});StreamingVSStorm处理模型,延迟:而Storm处理的是每次传入的一个事件,而SparkStreaming是处理某个时间段窗口内的事件流。因此,Storm处理一个事件可以达到秒内的延迟,而SparkStreaming则有几秒钟的延迟。容错、数据保证在容错数据保证方面的权衡是,SparkStreaming提供了更好的支持容错状态计算。在Storm中,每个单独的记录当它通过系统时必须被跟踪,所以Storm能够至少保证每个记录将被处理一次,但是在从错误中恢复过来时候允许出现重复记录。这意味着可变状态可能不正确地被更新两次。如果你需要秒内的延迟,Storm是一个不错的选择,而且没有数据丢失。如果你需要有状态的计算,而且要完全保证每个事件只被处理一次,SparkStreaming则更好。实现,编程apiStorm初次是由Clojure实现,而SparkStreaming是使用Scala;clojure和scala都是在jvm上执行的,都有javaapi。产品支持Storm已经发布几年了,在Twitter从2011年运行至今,streaming是比较新的项目。集群管理集成尽管两个系统都运行在它们自己的集群上,SparkStreaming能运行在YARN上。单纯的性能比较没有意义
Storm简单介绍参见《Storm的简单介绍.docx》流式处理框架Flume:日志收集系统Kafka:分布式队列系统Sparkstreaming:Storm搭建框架的几点理解高可用性业务系统的融合:input和output处理速度和数据安全(不丢失)消息传递和分发:业务模型兼容性、扩展性、性能、功能综合情况,尽量简化系统Flume Flume是一个分布式、可靠、和高可用的海量日志聚合的系统,支持在系统中定制各类数据发送方,用于收集数据;同时,Flume提供对数据进行简单处理,并写到各种数据接受方(可定制)的能力。FlumeSources:ExecSource、JMS、syslog、AvroSource、HTTPSource、CustomSourceFlumeSink:HDFSSink、LoggerSink、FileRollSink、NullSink、HBaseSink、CustomSinkFlumeChannels:MemoryChannel、FileChannel、CustomChannelFlumeInterceptors:Timestamp、Host、Morphline、RegexFiltering、RegexExtractorKafkaKafka是一个高吞吐量分布式消息系统。kafk
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026陕西省西咸新区秦汉新城第三医院招聘备考题库及完整答案详解一套
- 2026云南保山市消防救援局政府专职消防员招聘29人备考题库(第二批)及一套参考答案详解
- 2026安徽国际商务职业学院招聘高层次人才8人备考题库含答案详解
- 2026江西现代职业技术学院高层次人才招聘40人备考题库及答案详解1套
- 2026江苏南京大学YJ20260358化学学院博士后招聘1人备考题库带答案详解
- 2026云南昭通市政务服务中心工作招聘2人备考题库及答案详解一套
- 超声振动辅助下圆弧形铣刀加工钛合金的性能与机理研究
- 2026年金融代工安全生产培训协议
- 2026年物联网营销系统集成合同
- 2026年新能源合规新能源建设协议
- 2026安徽省农村信用社联合社招聘笔试参考题库及答案详解
- 痰液及咳痰能力的评估
- 2026年新闻记者资格证及新闻写作相关知识综合检测题型(必刷)附答案详解
- 2026年幼儿园教师高级职称考试练习卷附答案
- 移动公司员工培训制度
- 《增材制造工艺制订与实施》课件-SLM后处理设备
- 厂房屋面防水施工安全方案
- (正式版)DB51∕T 3336-2025 《零散天然气橇装回收安全规范》
- 水利职工三问交流研讨发言材料
- 2026年中国礼品行业展望白皮书
- 南中医综评面试题库及答案书
评论
0/150
提交评论