MAPREDUCE-3451, 把fairScheduler引入到2.0.2-alpha, 本文介紹一下hadoop 2.0.2-alpha的fairscheduler. 包括調度算法和配置方法.
代碼
在org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair包下, 主要包括如下的類:
各個類作用的簡要描述:
1. AllocationConfigurationException, 如果配置文件出錯會拋出此異常.
2. AppSchedulable 一個可以提交task的實體, 繼承於Schedulable,
3. FairScheduler 調度器的主體部分
4. FairSchedulerConfiguration的配置常量和默認值
5. FairSchedulerEventLog 封裝了LOG, 用於把調度事件寫到指定的log文件中
6. FifoAppComparator 繼承於Comparator, 對比兩個AppSchedulable的大小, 首先是Priority, 然后是startTime, 最后對比ApplicationId.
7. FSQueue, fairscheduler中的組信息 類
8. FSQueueSchedulable繼承於Schedulable, 一個可以提交task的實體
9. FSSchedulerApp繼承於SchedulerApp, 從調度器的角度來看, 每個在RM中正在運行的應用程序都是此類的實例.
10. NewJobWeightBooster, 實現了WeightAdjuster接口, 用於更新AppSchedulable的權重, Weight.
11. QueueManager, 維護一個組隊列, 並提供更新方法, fairscheduler調用.
12. Schedulable一個可以提交task的實體
13. SchedulingAlgorithms, 工具類, 包括fair scheduler使用到的調度算法.
14. SchedulingMode, enum類型, 包括FAIR, FIFO. 每個組內的調度模式.
15. 接口WeightAdjuster, 權重修改接口
Fairscheduler的原理
當 NM (NodeManager的簡稱)向RM (ResourceManager的簡稱)發送心跳后, 會調用調度器的nodeUpdate()方法,流程如下:
1. Processing the newly launched containers
2. Process completed containers
3. Assign new containers
a) Check for reserved applications
Reserved, 預留的意思, If we have have an application that has reserved a resource on this node already, we try to complete the reservation.
b) Schedule if there are no reservations. schedule at queue which is furthest below fair share.
i. 這里首先獲取所有組(getQueueSchedulables), 然后對他們排序, 使用SchedulingAlgorithms. FairShareComparator類排序.
ii. 然后從第一個組開始, 把資源分配給它, 並開始組內分資源,
iii. 如果未分配給第一組, 則分給下一組, 如果分給了第一組, 則繼續到第一步. 若未分配給第一個組, 或重復分配給某一組, 或大於maxAssign, 則退出循環.
SchedulingAlgorithms.FairShareComparator排序算法
兩個組, 排序的規則是:
1. 一個需要資源, 另外一個不需要資源, 則需要資源的排前面
2. 若都需要資源的話, 對比 使用的內存占minShare的比例, 比例小的排前面, (即盡量保證達到minShare)
3. 若比例相同的話, 計算出使用量與權重的比例, 小的排前面, 即權重大的優先, 使用量小的優先.
4. 若還是相同, 提交時間早的優先, app id小的排前面.
配置方法
在RM的配置目錄下的yarn-site.xml文件中增加配置項
<property> <name>yarn.resourcemanager.scheduler.class</name> <value>org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.FairScheduler</value> </property>
在RM的配置目錄下新建fair-scheduler.xml文件, 增加如下內容:
<?xml version="1.0"?> <allocations> <queue name="sample_queue"> <minResources>1000</minResources> <maxResources>9000</maxResources> <maxRunningApps>50</maxRunningApps> <weight>2.0</weight> <schedulingMode>fair</schedulingMode> <aclSubmitApps> sample_queue,yuling.sh</aclSubmitApps> <aclAdministerApps> sample_queue,yuling.sh</aclAdministerApps> </queue> <queue name="default"> <minResources>1000</minResources> <maxResources>9000</maxResources> <maxRunningApps>50</maxRunningApps> <weight>2.0</weight> <schedulingMode>fair</schedulingMode> <aclSubmitApps> yuling.sh</aclSubmitApps> <aclAdministerApps> a</aclAdministerApps> </queue> <userMaxAppsDefault>5</userMaxAppsDefault> </allocations>
注意, 在yarn中, 提交作業的組驗證已經放到了調度器中實現.
轉載請注明出處:http://www.cnblogs.com/shenh062326/archive/2012/12/09/2810010.html