厚街網(wǎng)站建設(shè)多少錢百度的seo關(guān)鍵詞優(yōu)化怎么弄
大數(shù)據(jù)-學(xué)習(xí)實(shí)踐-5企業(yè)級(jí)解決方案
(大數(shù)據(jù)系列)
文章目錄
- 大數(shù)據(jù)-學(xué)習(xí)實(shí)踐-5企業(yè)級(jí)解決方案
- 1知識(shí)點(diǎn)
- 2具體內(nèi)容
- 2.1小文件問題
- 2.1.1 SequenceFile
- 2.1.2 MapFile
- 2.1.3 小文件存儲(chǔ)計(jì)算
- 2.2數(shù)據(jù)傾斜
- 2.3 YARN
- 2.3.1 YARN架構(gòu)
- 2.3.2 YARN調(diào)度器
- 2.3.2 YARN多資源隊(duì)列配置和使用
- 2.4Hadoop官方文檔
- 2.5總結(jié)
- 3待補(bǔ)充
- 4Q&A
- 5code
- 6參考
1知識(shí)點(diǎn)
- 小文件問題
- 小文件存儲(chǔ)計(jì)算
- 數(shù)據(jù)傾斜
- YARN
- Hadoop官方
2具體內(nèi)容
2.1小文件問題
MapReduce框架針對(duì)大數(shù)據(jù)文件設(shè)計(jì),小文件處理效率低下,消耗內(nèi)存資源
- 每個(gè)小文件在NameNode都會(huì)占用150字節(jié)的內(nèi)存,每個(gè)小文件都是一個(gè)block
- 一個(gè)block產(chǎn)生一個(gè)inputsplit,產(chǎn)生一個(gè)Map任務(wù)
- 同時(shí)啟動(dòng)多個(gè)map任務(wù)消耗性能,影響MapReduce執(zhí)行效率
2.1.1 SequenceFile
- SequenceFile是二進(jìn)制文件,直接將<k,v>對(duì)序列化到文件
- 對(duì)小文件進(jìn)行文件合并:文件名為k,文件內(nèi)容為v,序列化到大文件
- 但需要合并文件的過程,文件大且合并后的文件不便查看,需要遍歷查看每個(gè)小文件
- 讀、寫試驗(yàn)
- SequenceFile在hdfs上合并為一個(gè)文件
2.1.2 MapFile
- 排序后的MapFile,包括index和data
- index為文件的數(shù)據(jù)索引,記錄每個(gè)record的key值,并保存該record在文件中的偏移位
- 訪問MapFile時(shí),索引文件被加載到內(nèi)存,通過索引映射關(guān)系快速定位到指定Record所在文件位置
- 相對(duì)SequenceFile而言,MapFile的檢索效率是高效的,缺點(diǎn)是會(huì)消耗一部分內(nèi)存來存儲(chǔ)index數(shù)據(jù)
- MapFile在hdfs上包括2個(gè)文件,index和data
2.1.3 小文件存儲(chǔ)計(jì)算
使用SequenceFile實(shí)現(xiàn)小文件存儲(chǔ)計(jì)算
- java開發(fā),生成SequenceFile;(人工將一堆小文件處理成一個(gè)較大文件,進(jìn)行MapReduce計(jì)算)
- 開發(fā)MapReduce(借助底層),讀取Sequencefile,進(jìn)行分布式計(jì)算
2.2數(shù)據(jù)傾斜
- 一般不對(duì)Map任務(wù)進(jìn)行改動(dòng),但為了提高效率,可增加Reduce任務(wù),需要對(duì)數(shù)據(jù)分區(qū)
- job.getPartitionerClass()實(shí)現(xiàn)分區(qū)
- 當(dāng)MapReduce程序執(zhí)行時(shí),大部分Reduce節(jié)點(diǎn)執(zhí)行完畢,但有一個(gè)或幾個(gè)Reduce節(jié)點(diǎn)運(yùn)行很慢,導(dǎo)致整個(gè)程序處理時(shí)間變長(zhǎng),表現(xiàn)為Reduce節(jié)點(diǎn)卡著不動(dòng)
- 傾斜不嚴(yán)重,可增加Reduce任務(wù)個(gè)數(shù)
job.setNumReduceTasks(Integer.parseInt(args[2]));
- 傾斜嚴(yán)重,要把傾斜數(shù)據(jù)打散(抽樣確定哪一類,打散)
String key = words[0];
if ("5".equals(key)) {//把傾斜的key打散,分成10份key = "5" + "_" + random.nextInt(10);
}
2.3 YARN
2.3.1 YARN架構(gòu)
- 集群資源的管理和調(diào)度,支持主從架構(gòu),主節(jié)點(diǎn)最多2個(gè),從節(jié)點(diǎn)可多個(gè)
- ResourceManager:主節(jié)點(diǎn)負(fù)責(zé)集群資源分配和管理
- NodeManager:從節(jié)點(diǎn)負(fù)責(zé)當(dāng)前機(jī)器資源管理
- YARN主要管理內(nèi)存和CPU兩種資源
- NodeManager啟動(dòng)向ResourceManager注冊(cè),注冊(cè)信息包含該節(jié)點(diǎn)可分配的CPU和內(nèi)存總量
- 默認(rèn)單節(jié)點(diǎn):(yarn-site.xml文件中設(shè)置)
- yarn.nodemanager.resourece.memory-mb:單節(jié)點(diǎn)可分配物理內(nèi)存總量,默認(rèn)8Mb*1024,8G
- yarn.nodemanager.resource.cpu-vcores:單節(jié)點(diǎn)可分配的虛擬CPU個(gè)數(shù),默認(rèn)是8
2.3.2 YARN調(diào)度器
- FIFO Scheduler 先進(jìn)先出
- Capacity Scheduler FIFO Scheduler 多隊(duì)列版本(常用)
- Fair Scheduler 多隊(duì)列,多用戶共享資源
2.3.2 YARN多資源隊(duì)列配置和使用
- 增加online隊(duì)列和offline隊(duì)列
- 修改 capacity-scheduler.xml 文件,并同步其他節(jié)點(diǎn)
<property><name>yarn.scheduler.capacity.root.queues</name><value>default,online,offline</value><description>The queues at the this level (root is the root queue).</description>
</property>
<property><name>yarn.scheduler.capacity.root.default.capacity</name><value>70</value><description>Default queue target capacity.</description>
</property>
<property><name>yarn.scheduler.capacity.root.online.capacity</name><value>10</value><description>Online queue target capacity.</description>
</property>
<property><name>yarn.scheduler.capacity.root.offline.capacity</name><value>20</value><description>Offline queue target capacity.</description>
</property>
<property><name>yarn.scheduler.capacity.root.default.maximum-capacity</name><value>70</value><description>The maximum capacity of the default queue.</description>
</property>
<property><name>yarn.scheduler.capacity.root.online.maximum-capacity</name><value>10</value><description>The maximum capacity of the online queue.</description>
</property>
<property><name>yarn.scheduler.capacity.root.offline.maximum-capacity</name><value>20</value><description>The maximum capacity of the offline queue.</description>
</property>
- 重新啟動(dòng)
stop-all.sh
start-all.sh
- 向offline隊(duì)列提交MR任務(wù)
- online隊(duì)列里面運(yùn)行實(shí)時(shí)任務(wù)
- offline隊(duì)列里面運(yùn)行離線任務(wù)
#解析命令行通過-D傳遞參數(shù),添加至conf;也可修改java程序解析各參數(shù)
String[] remainingArgs = new GenericOptionsParser(conf,args).getRemainingArgs();
Job job = Job.getInstance(conf);
job.setJarByClass(WordCountJobQueue.class);#必須有,否則集群執(zhí)行時(shí)找不到wordCountJob這個(gè)類
#重新編譯上傳執(zhí)行
hadoop jar db_hadoop-1.0-SNAPSHOT-jar-with-dependencies.jar com.imooc.mr.WordCountJobQueue -Dmapreduce.job.queue=offline /test/hello.txt /outqueue
2.4Hadoop官方文檔
- 官方文檔
- 在CDH中的使用
- 在HDP中的使用
-(1080端口) Ambari組件,提供web界面
2.5總結(jié)
- MapReduce
- 原理
- 計(jì)算過程
- 執(zhí)行步驟
- wordcount案例
- 日志查看:開啟YARN日志聚合,啟動(dòng)historyServer進(jìn)程
- 程序擴(kuò)展:去掉Reduce
- Shuffle過程
- 序列化
- Writable實(shí)現(xiàn)類
- 特點(diǎn)
- 源碼分析
- InputFormat
- OutputFormat
- 性能優(yōu)化
- 小文件
- 數(shù)據(jù)傾斜
- YARN
- 資源管理:內(nèi)存+CPU
- 調(diào)度器:常用CapacityScheduler
3待補(bǔ)充
無
4Q&A
無
5code
無
6參考
- 大數(shù)據(jù)課程資料