




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
SparkStreaming
Large-scalenear-real-timestreamprocessing
TathagataDas(TD)UCBerkeleyUCBERKELEYWhatisSparkStreaming?FrameworkforlargescalestreamprocessingScalesto100sofnodesCanachievesecondscalelatenciesIntegrateswithSpark’sbatchandinteractiveprocessingProvidesasimplebatch-likeAPIforimplementingcomplexalgorithmCanabsorblivedatastreamsfromKafka,Flume,ZeroMQ,etc.
MotivationManyimportantapplicationsmustprocesslargestreamsoflivedataandprovideresultsinnear-real-timeSocialnetworktrendsWebsitestatisticsIntrustiondetectionsystemsetc.RequirelargeclusterstohandleworkloadsRequirelatenciesoffewsecondsNeedforaframework……forbuildingsuchcomplexstreamprocessingapplicationsButwhataretherequirementsfromsuchaframework?RequirementsScalable
tolargeclustersSecond-scalelatenciesSimple
programmingmodelCasestudy:Conviva,Inc.Real-timemonitoringofonlinevideometadataHBO,ESPN,ABC,SyFy,…TwoprocessingstacksCustom-builtdistributedstreamprocessingsystem1000scomplexmetricsonmillionsofvideosessionsRequiresmanydozensofnodesforprocessingHadoopbackendforofflineanalysisGeneratingdailyandmonthlyreportsSimilarcomputationasthestreamingsystemCustom-builtdistributedstreamprocessingsystem1000scomplexmetricsonmillionsofvideossessionsRequiresmanydozensofnodesforprocessingHadoopbackendforofflineanalysisGeneratingdailyandmonthlyreportsSimilarcomputationasthestreamingsystemCasestudy:XYZ,Inc.AnycompanywhowantstoprocesslivestreamingdatahasthisproblemTwicetheefforttoimplementanynewfunctionTwicethenumberofbugstosolveTwicetheheadacheTwoprocessingstacksRequirementsScalable
tolargeclustersSecond-scalelatenciesSimple
programmingmodelIntegrated
withbatch&interactiveprocessingStatefulStreamProcessingTraditionalstreamingsystemshaveaevent-drivenrecord-at-a-timeprocessingmodelEachnodehasmutablestateForeachrecord,updatestate&sendnewrecordsStateislostifnodedies!Makingstatefulstreamprocessingbefault-tolerantischallengingmutablestatenode1node3inputrecordsnode2inputrecords9ExistingStreamingSystemsStormReplaysrecordifnotprocessedbyanodeProcesseseachrecordatleastonceMayupdatemutablestatetwice!Mutablestatecanbelostduetofailure!Trident–UsetransactionstoupdatestateProcesseseachrecordexactlyoncePerstatetransactionupdatesslow10RequirementsScalable
tolargeclustersSecond-scalelatenciesSimple
programmingmodelIntegrated
withbatch&interactiveprocessingEfficientfault-tolerance
instatefulcomputationsSparkStreaming12DiscretizedStreamProcessingRunastreamingcomputationasaseriesofverysmall,deterministicbatchjobs13SparkSparkStreamingbatchesofXsecondslivedatastreamprocessedresultsChopupthelivestreamintobatchesofXsecondsSparktreatseachbatchofdataasRDDsandprocessesthemusingRDDoperationsFinally,theprocessedresultsoftheRDDoperationsarereturnedinbatchesDiscretizedStreamProcessingRunastreamingcomputationasaseriesofverysmall,deterministicbatchjobs14SparkSparkStreamingbatchesofXsecondslivedatastreamprocessedresultsBatchsizesaslowas?second,latency~1secondPotentialforcombiningbatchprocessingandstreamingprocessinginthesamesystemExample1–GethashtagsfromTwitterval
tweets
=ssc.twitterStream(<Twitterusername>,<Twitterpassword>)DStream:asequenceofRDDrepresentingastreamofdatabatch@t+1batch@tbatch@t+2tweetsDStreamstoredinmemoryasanRDD(immutable,distributed)TwitterStreamingAPIExample1–GethashtagsfromTwittervaltweets=ssc.twitterStream(<Twitterusername>,<Twitterpassword>)val
hashTags
=tweets.flatMap
(status=>getTags(status))flatMapflatMapflatMap…transformation:modifydatainoneDstreamtocreateanotherDStream
newDStreamnewRDDscreatedforeverybatchbatch@t+1batch@tbatch@t+2tweetsDStreamhashTags
Dstream[#cat,#dog,…]Example1–GethashtagsfromTwittervaltweets=ssc.twitterStream(<Twitterusername>,<Twitterpassword>)val
hashTags=tweets.flatMap(status=>getTags(status))hashTags.saveAsHadoopFiles("hdfs://...")outputoperation:topushdatatoexternalstorageflatMapflatMapflatMapsavesavesavebatch@t+1batch@tbatch@t+2tweetsDStreamhashTagsDStreameverybatchsavedtoHDFSJavaExampleScalaval
tweets
=ssc.twitterStream(<Twitterusername>,<Twitterpassword>)val
hashTags
=tweets.flatMap
(status=>getTags(status))hashTags.saveAsHadoopFiles("hdfs://...")JavaJavaDStream<Status>tweets=ssc.twitterStream(<Twitterusername>,<Twitterpassword>)JavaDstream<String>hashTags
=tweets.flatMap(newFunction<...>{})hashTags.saveAsHadoopFiles("hdfs://...")FunctionobjecttodefinethetransformationFault-toleranceRDDsarerememberthesequenceofoperationsthatcreateditfromtheoriginalfault-tolerantinputdataBatchesofinputdataarereplicatedinmemoryofmultipleworkernodes,thereforefault-tolerantDatalostduetoworkerfailure,canberecomputedfrominputdatainputdatareplicatedinmemoryflatMaplostpartitionsrecomputedonotherworkerstweetsRDDhashTagsRDDKeyconceptsDStream–sequenceofRDDsrepresentingastreamofdataTwitter,HDFS,Kafka,Flume,ZeroMQ,AkkaActor,TCPsocketsTransformations–modifydatafromonDStreamtoanotherStandardRDDoperations–map,countByValue,reduce,join,…Statefuloperations–window,countByValueAndWindow,…OutputOperations–senddatatoexternalentitysaveAsHadoopFiles–savestoHDFSforeach–doanythingwitheachbatchofresultsExample2–Countthehashtagsvaltweets=ssc.twitterStream(<Twitterusername>,<Twitterpassword>)val
hashTags=tweets.flatMap(status=>getTags(status))val
tagCounts=hashTags.countByValue()flatMapmapreduceByKeyflatMapmapreduceByKey…flatMapmapreduceByKeybatch@t+1batch@tbatch@t+2hashTagstweetstagCounts[(#cat,10),(#dog,25),...]Example3–Countthehashtagsoverlast10minsvaltweets=ssc.twitterStream(<Twitterusername>,<Twitterpassword>)val
hashTags=tweets.flatMap(status=>getTags(status))val
tagCounts=hashTags.window(Minutes(10),Seconds(1)).countByValue()slidingwindowoperationwindowlengthslidingintervaltagCountsExample3–Countingthehashtagsoverlast10minsval
tagCounts
=hashTags.window(Minutes(10),Seconds(1)).countByValue()hashTagst-1tt+1t+2t+3slidingwindowcountByValuecountoverallthedatainthewindow?Smartwindow-basedcountByValueval
tagCounts=hashtags.countByValueAndWindow(Minutes(10),Seconds(1))
hashTagst-1tt+1t+2t+3++–countByValueaddthecountsfromthenewbatchinthewindowsubtractthecountsfrombatchbeforethewindowtagCountsSmartwindow-basedreduceTechniquetoincrementallycomputecountgeneralizestomanyreduceoperationsNeedafunctionto“inversereduce”(“subtract”forcounting)Couldhaveimplementedcountingas:
hashTags.reduceByKeyAndWindow(_+_,_-_,Minutes(1),…)25DemoFault-tolerantStatefulProcessingAllintermediatedataareRDDs,hencecanberecomputediflost
hashTagst-1tt+1t+2t+3tagCountsFault-tolerantStatefulProcessingStatedatanotlostevenifaworkernodediesDoesnotchangethevalueofyourresultExactlyoncesemanticstoalltransformationsNodoublecounting!28OtherInterestingOperationsMaintainingarbitrarystate,tracksessionsMaintainper-usermoodasstate,andupdateitwithhis/hertweets
tweets.updateStateByKey(tweet=>updateMood(tweet))DoarbitrarySparkRDDcomputationwithinDStreamJoinincomingtweetswithaspamfiletofilteroutbadtweets
tweets.transform(tweetsRDD=>{
tweetsRDD.join(spamHDFSFile).filter(...)})PerformanceCanprocess6GB/sec(60Mrecords/sec)ofdataon100nodesatsub-secondlatencyTestedwith100streamsofdataon100EC2instanceswith4coreseach30ComparisonwithStormandS4HigherthroughputthanStormSparkStreaming:670krecords/second/nodeStorm:115krecords/second/nodeApacheS4:7.5krecords/second/node31FastFaultRecoveryRecoversfromfaults/stragglerswithin1sec32RealApplications:ConvivaReal-timemonitoringofvideometadata33Achieved1-2secondlatencyMillionsofvideosessionsprocessedScaleslinearlywithclustersizeRealApplications:MobileMillenniumProjectTraffictransittimeestimationusingonlinemachinelearningonGPSobservations34MarkovchainMonteCarlosimulationsonGPSobservationsVeryCPUintensive,requiresdozensofmachinesforusefulcomputationScaleslinearlywithclustersizeVision-onestacktorulethemallAd-hocQueriesBatchProcessingStreamProcessingSpark+Shark+SparkStreamingSparkprogramvsSparkStreamingprogramSparkStreamingprogramonTwitterstreamval
tweets
=ssc.twitterStream(<Twitterusername>,<Twitterpassword>)val
hashTags
=tweets.flatMap
(status=>getTags(status))hashTags.saveAsHadoopFiles("hdfs://...")SparkprogramonTwitterlogfileval
tweets
=sc.hadoopFile("hdfs://...")val
hashTags
=tweets.flatMap
(status=>getTags(status))hashTags.saveAsHadoopFile("hdfs://...")Vision-onestacktorulethemallExploredatainteractivelyusingSparkShell/PySparktoidentifyproblemsUsesamecodeinSparkstand-aloneprogramstoidentifyproblemsinproductionlogsUsesimilarcodeinSparkStreamingtoidentifyproblemsinlivelogstreams$./spark-shellscala>valfile=sc.hadoopFile(“smallLogs”)...scala>valfiltered=file.filter(_.contains(“ERROR”))...scala>valmapped=file.map(...)...objectProcessProductionData{
defmain(args:Array[String]){
val
sc=newSparkContext(...)
valfile=sc.hadoopFile(“productionLogs”)
valfiltered=file.filter(_.contains(“ERROR”))
valmapped=file.map(...)...}}objectProcessLiveStream{
defmain(args:Array[String]){
val
sc=newStreamingContext(...)
valstream=sc.kafkaStream(...)
valfiltered=file.filter(_.contains(“ERROR”))
valmapped=file.map(...)...}}Vision-onestacktorulethemallExploredatainteractivelyusingSparkShell/PySparktoidentifyproblemsUsesamecodeinSparkstand-aloneprogramstoidentifyproblemsinproductionlogsUsesimilarcodeinSparkStreamingtoidentifyproblemsinlivelogstreams$./spark-shellscala>valfile=sc.hadoopFile(“smallLogs”)...scala>valfiltered=
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年度房產(chǎn)抵押小微企業(yè)貸款合同模板
- 2025年度兒童房安全木門定制合同
- 2025年度專利技術(shù)許可協(xié)議模板-智能硬件
- 2025年度家具行業(yè)專利技術(shù)許可合同
- 冷藏肉類電商運輸合同
- 2025年度導(dǎo)演聘用合同范例:院線電影導(dǎo)演合作協(xié)議書
- 2025年吉安職業(yè)技術(shù)學院單招職業(yè)傾向性測試題庫完整
- 2025年度農(nóng)業(yè)種植合同解除協(xié)議樣本
- 親子教育居間合同
- 2025年度文化旅游產(chǎn)業(yè)投資合作協(xié)議書范文
- 過渡金屬氧化物催化劑及其催化作用
- 溫濕度對果蔬儲存的影響
- 海運客服專員崗位職責
- 電是怎么產(chǎn)生的
- 新概念英語第一冊課文完整版
- 急救藥品搶救藥品培訓(xùn)
- 人教鄂教版三年級下冊科學全冊教案
- 如何做好一名優(yōu)秀的項目經(jīng)理
- (完整word版)中考定語從句精講+練習答案
- 醫(yī)師簽名(簽章)留樣備案表
- 0~6歲兒童眼保健和視力檢查標準技術(shù)操作
評論
0/150
提交評論