版權(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)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 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江蘇南京醫(yī)科大學第四附屬醫(yī)院(南京市浦口醫(yī)院)招聘高層次人才5人參考筆試題庫附答案解析
- 2025年南昌市第一醫(yī)院編外專技人才自主招聘1人模擬筆試試題及答案解析
- 2026年寶雞智博學校教師招聘模擬筆試試題及答案解析
- 2025北京同仁堂鄂爾多斯市藥店有限公司招聘10人備考筆試題庫及答案解析
- 2025廣東佛山市順德區(qū)樂從鎮(zhèn)沙滘小學招文員1人參考筆試題庫附答案解析
- 2025河南開封職業(yè)學院招聘專職教師81人模擬筆試試題及答案解析
- 臨床急性肺栓塞早期識別與護理
- 甘肅能源化工投資集團有限公司2026屆校園招聘183人考試參考試題及答案解析
- 2025云南保山隆陽區(qū)紅十字會招聘公益性崗位人員1人參考考試題庫及答案解析
- 2025廣西桂林電子科技大學第二批教職人員控制數(shù)工作人員招聘32人備考筆試試題及答案解析
- 2025至2030中國正畸矯治器行業(yè)項目調(diào)研及市場前景預測評估報告
- 《國家十五五規(guī)劃綱要》全文
- GB/T 46194-2025道路車輛信息安全工程
- 2025年國考《行測》全真模擬試卷一及答案
- 國家開放大學2025年商務英語4綜合測試答案
- 2025年國家開放大學《合同法》期末考試備考題庫及答案解析
- 鋁合金被動門窗施工方案
- 留置看護輔警相關(guān)刷題
- 交警輔警談心談話記錄模板范文
- 基于SLP法的京東物流園3C類倉庫布局優(yōu)化研究
- 2025年《公差配合與技術(shù)測量》(習題答案)
評論
0/150
提交評論