strata-spark-streaming-大數(shù)據(jù)文檔資料_第1頁
strata-spark-streaming-大數(shù)據(jù)文檔資料_第2頁
strata-spark-streaming-大數(shù)據(jù)文檔資料_第3頁
strata-spark-streaming-大數(shù)據(jù)文檔資料_第4頁
strata-spark-streaming-大數(shù)據(jù)文檔資料_第5頁
已閱讀5頁,還剩35頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(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. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論