資源描述:
《陳超-Spark Summit China》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在學(xué)術(shù)論文-天天文庫。
1、Spark內(nèi)核探索與性能優(yōu)化陳超@CrazyJvmSparkSummitChinaDidyouknow?cache/persistislazy!unpersistiseager!Didyouknow?groupByKey:notcombinelocally!reduceByKey:combinelocallyDidyouknow?vallevel=MEMORY_AND_DISKwillnotspilldatatodiskimmediatelyafteryoucallsc.persist(level)!Didyouknow?Howtodecidetaskn
2、umber?!if…elseif…else…Let’sgo!!!再看RDD!分區(qū)protecteddefgetPartitions:Array[Partition]!依賴protecteddefgetDependencies:Seq[Dependency[_]]=deps!函數(shù)defcompute(split:Partition,context:TaskContext):Iterator[T]!最佳位置(可選)protecteddefgetPreferredLocations(split:Partition):Seq[String]=Nil!分區(qū)策略(可
3、選)@transientvalpartitioner:Option[Partitioner]=None7HadoopRDD?分區(qū):每個(gè)HDFSblock?依賴:無?函數(shù):讀取每一個(gè)block?最佳位置:HDFSblock所在位置?分區(qū)策略:無8FilteredRDD?分區(qū):與父RDD一致?依賴:與父RDD一對(duì)一?函數(shù):計(jì)算父RDD的每個(gè)分區(qū)并過濾?最佳位置:無(與父RDD一致)?分區(qū)策略:無9JoinedRDD?分區(qū):每個(gè)reduce任務(wù)一個(gè)分區(qū)?依賴:依賴所有父RDD?函數(shù):讀取shuf?e數(shù)據(jù)并計(jì)算?最佳位置:無可以指定Partitioner?分區(qū)策
4、略:HashPartitioner(partitions:Int)10ClusterOverviewWorkerNodeExecutorCacheTaskTaskDriverProgramSparkContextClusterManagerWorkerNodeExecutorCacheTaskTask11核心組件Sparkclient!(appmaster)SparkworkerRDDgraphYourprogramCluster!TaskThreadsSchedulermanagervalsc=newSparkContext!valdata=sc.te
5、xtFile(“…”)!data.?lter(…).countTaskThreadsBlocktrackerShuf?etrackerHDFS,HBase,…12CODEvalconf=newSparkConf()conf.setMaster(“spark://....”).setAppName(“Analysis”).setSparkHome(“…”).setJars(“…”)valsc=newSparkContext(conf)vallines=sc.testFile(“hdfs://...“)!valerrors=lines.?lter(_.sta
6、rtsWith(“ERROR”))!errors.cache()!mysql_error=errors.?lter(_.contains(“MySQL”)).count!http_errors=errors.?lter(_.contains(“Http”)).countRDD圖每個(gè)partition都會(huì)分配一個(gè)task數(shù)據(jù)層面Partition層面HadoopRDD?le:path=hdfs://…FilteredRDDerrors:func=_.contains(…)rdd.cacheTask1Task2Task3……14數(shù)據(jù)本地性第一次運(yùn)行時(shí)數(shù)據(jù)不在
7、內(nèi)存中,所以文件系統(tǒng)本地性從HDFS上取,任務(wù)最好運(yùn)行在數(shù)據(jù)所在的節(jié)點(diǎn)上!內(nèi)存本地性第二次運(yùn)行,數(shù)據(jù)已經(jīng)在內(nèi)存中,所以任務(wù)最好運(yùn)行在該數(shù)據(jù)所在內(nèi)存的節(jié)點(diǎn)上。LRU置換萬一有數(shù)據(jù)被置換出內(nèi)存,則仍然從HDFS上取。15任務(wù)調(diào)度!16DAGScheduler目標(biāo)RDD計(jì)算每個(gè)分區(qū)的函數(shù)結(jié)果偵聽器!!DAGScheduler?根據(jù)DAG構(gòu)建Stage,決定每個(gè)任務(wù)的最佳位置?將taskset傳給底層調(diào)度器TaskScheduler?重新提交shuf?e輸出丟失的stage17調(diào)度器優(yōu)化灰顏色代表之前已經(jīng)算好的分區(qū)!??一個(gè)Stage內(nèi)的窄依賴進(jìn)行pipelin
8、e操作1+1+1+1=4①1+1=2;2+1=3;3+1=4②?重用已經(jīng)緩存過的