1. 程式人生 > >Yarn公平排程器[轉自 AIMP平臺wiki]

Yarn公平排程器[轉自 AIMP平臺wiki]

Yarn公平排程器

預設,基於記憶體做公平排程。可以配置成基於記憶體和CPU。
只有一個作業時,它使用整個系統的資源;新的作業提交後,被釋放的資源就會分配給它,最終每個作業獲得同樣的資源。
這會讓短時作業在合理時間內完成,並不會“餓著”長時間的作業。
公平排程器也支援優先順序、它作為作業獲得叢集資源的權值。

佇列可用配置最小保證資源,以保證某些使用者、作業總能得到足夠的資源。
配置可以限制使用者、佇列中同時可以執行的作業數。這點主要用於當用戶一下提交過多作業時或者執行大量作業,
導致大量中間檔案或者不斷切換上下文,改善系統的效能問題。
限制同時執行的作業數目不會導致作業提交失敗,只會等著使用者下的作業執行完成才會參與排程。

佇列支援層級結構--schedule-allocation檔案配置
所有佇列繼承自root佇列。父佇列的資源按照公平排程器的模式分配給子佇列,只有葉子佇列能執行作業。
佇列名:root.parent1.queue1 即由父佇列名拼成
可以擴充套件org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.SchedulingPolicy建立自己的排程策略。

管理:
1、allocation檔案可以修改,系統會在修改後10-15秒後自動重新載入檔案。可修改包括 minimum shares, limits, weights, preemption timeouts等。
2、

http://ResourceManager URL/cluster/scheduler可以檢視資源排程情況。
包括:queue中的container使用的資源量、active的應用的個數(至少有一個container,類似slot概念?),pendind的應用個數(即一個container都沒有的)
佇列的最新保證資源、佇列能用的最大資源、等

Allocatioin檔案的配置
minResources:佇列最小資源保證量,格式為:"X mb, Y vcores"。單資源公平排程模式下,vcores被忽略。
如果當前佇列的記憶體數沒有滿足,則此佇列的記憶體優先滿足。
Under dominant resource fairness, a queue is considered unsatisfied if its usage for its dominant resource with respect to the cluster capacity is below its minimum share for that resource.
當多個佇列不滿足條件,已有資源量/最小資源量 值越小越優先。
maxResources:佇列能使用資源最大量。
maxRunningApps:佇列中同時執行應用最大數
schedulingPolicy:排程策略fifo,fair,drf。fifo則先提交先排程,後提交的只有系統有多餘的資源時會被排程。
aclSubmitApps:控制哪個使用者能提交作業到佇列,逗號分割。子佇列會繼承父佇列的ACL
aclAdministerApps:也要配置??怎麼用,待調查。
minSharePreemptionTimeout:資源搶佔超時時間,超過這個時間不能再搶?

User elements, which represent settings governing the behavior of individual users. They can contain a single property: maxRunningApps, a limit on the number of running apps for a particular user.
A userMaxAppsDefault element, which sets the default running app limit for any users whose limit is not otherwise specified.
A fairSharePreemptionTimeout element, number of seconds a queue is under its fair share before it will try to preempt containers to take resources from other queues.
A defaultQueueSchedulingPolicy element, which sets the default scheduling policy for queues; overriden by the schedulingPolicy element in each queue if specified. Defaults to "fair".

安裝

yarn-site.xml中配置如下

<property>
<name>yarn.resourcemanager.scheduler.class</name>
<value>org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.FairScheduler</value>
</property>
<property> 
<name>yarn.scheduler.fair.allocation.file</name> 
<value>{HADOOP_CONF_DIR}/fair-allocation.xml</value>
<description>fair-allocation.xml 檔案是對每一個佇列的屬性配置</description>
</property> 
<property> 
<name>yarn.scheduler.fair.user-as-default-queue</name>
<description>如果希望以使用者名稱作為佇列,可以將該屬性配置為true,預設為true,所以如果不想以使用者名稱為佇列的,必須顯式的設定成false</description> 
<value>false</value> 
</property> 
<property> 
<name>yarn.scheduler.fair.preemption</name>
<description>是否可搶佔,如果某個佇列配置的最小資源量沒有達到,使用者提交的作業可以搶佔別的佇列正在運作的任務的資源。建議不要設定成true,會造成叢集資源浪費,並且目前該功能還在進一步完善,預設 false。</description> 
<value>false</value> 
</property> 
<property> 
<name>yarn.scheduler.fair.sizebasedweight</name>
<description>以作業的規模大小作為排程的權值,預設為false</description> 
<value>true</value> 
</property> 
<property> 
<name>yarn.scheduler.fair.assignmultiple</name>
<description>一次心跳響應是否允許分配多個container,預設為false</description> 
<value>true</value> 
</property> 
<property> 
<name>yarn.scheduler.fair.max.assign</name>
<description>如果一次心跳響應允許分配多個container,一次最多允許分配的container數,預設為-1,沒有限制</description> 
<value>-1</value> 
</property> 
<property> 
<name>yarn.scheduler.fair.locality.threshold.node</name>
<description>fair 允許等待nodelocal排程的次數,這個配置是叢集節點數的比例值。比如說叢集100臺,為達到某個作業的datalocal排程,允許等待10次。大於10就強制排程</description> 
<value>0.1</value> 
</property> 
<property> 
<name>yarn.scheduler.fair.locality.threshold.rack</name>
<description>類似於yarn.scheduler.fair.locality.threshold.node的配置,這個是為了排程racklocal的任務</description> 
<value>0.1</value> 
</property>

yarn.nodemanager.resource.memory-mb 表示該節點上YARN可使用的實體記憶體總量,預設是8192(MB),yarn不能識別實體記憶體總量,需要手工配置。
yarn.nodemanager.resource.cpu-vcores 表示該節點上YARN可使用的虛擬CPU個數,預設是8,推薦將該值設值為與物理CPU核數數目相同

fair-allocation.xml簡單配置例:

<?xml version="1.0"?>
<allocations>
  <queue name="cdh5">
    <minResources>100 mb,1vcores</minResources>
    <maxResources>90000 mb,8vcores</maxResources>
    <maxRunningApps>50</maxRunningApps>
    <weight>1.0</weight>
    <schedulingPolicy>fair</schedulingPolicy>
  </queue>
  <queue name="ocnosql">
    <minResources>100 mb,1vcores</minResources>
    <maxResources>300 mb,2vcores</maxResources>
    <maxRunningApps>10</maxRunningApps>
    <weight>1.0</weight>
    <schedulingPolicy>fair</schedulingPolicy>
  </queue>

  <user name="cdh5">
    <maxRunningApps>30</maxRunningApps>
  </user>
  <userMaxAppsDefault>5</userMaxAppsDefault>

  <queuePlacementPolicy>
    <rule name="specified" />
    <rule name="primaryGroup" create="false" />
    <rule name="default" />
  </queuePlacementPolicy>
</allocations>

兩個佇列cdh5和ocnoql,配置不同資源使用量,預設提交任務的組名和佇列名對應。

hive中set mapred.job.queue.name=指定佇列 ( hive --hiveconf mapreduce.job.queuename=queue1)

關於acl控制:
子佇列的許可權可以繼承父佇列,即使子佇列設定自己的許可權控制,還是會與父佇列的許可權取並集。而root佇列是所有佇列的父佇列,他的許可權是所有使用者都可以提交作業、管理作業。所以,子佇列的許可權設定是不起作用的。必須顯式設定root佇列許可權

<?xml version="1.0"?>
<allocations>
  <queue name="root">  
    <minResources>10000mb,10vcores</minResources>  
    <maxResources>90000mb,100vcores</maxResources>  
    <maxRunningApps>50</maxRunningApps>  
    <weight>2.0</weight>  
    <schedulingMode>fair</schedulingMode>  
    <aclSubmitApps> </aclSubmitApps>  
    <aclAdministerApps> </aclAdministerApps>

  <queue name="cdh5">
    <minResources>100 mb,1vcores</minResources>
    <maxResources>5000 mb,5vcores</maxResources>
    <maxRunningApps>50</maxRunningApps>
    <weight>2.0</weight>
    <schedulingPolicy>fair</schedulingPolicy>
                <aclAdministerApps>cdh5 cdh5</aclAdministerApps>
                <aclSubmitApps>cdh5 cdh5</aclSubmitApps>
<!--
    <queue name="sample_sub_queue">
      <aclSubmitApps>cdh5</aclSubmitApps>
      <minResources>5000 mb,0vcores</minResources>
        <maxResources>9000 mb,4vcores</maxResources>
    </queue>
-->
  </queue>
  <queue name="ocnosql">
    <minResources>100 mb,1vcores</minResources>
    <maxResources>2000 mb,2vcores</maxResources>
    <maxRunningApps>10</maxRunningApps>
    <weight>1.0</weight>
    <schedulingPolicy>fair</schedulingPolicy>
        <aclAdministerApps>ocnosql</aclAdministerApps>
                <aclSubmitApps>ocnosql</aclSubmitApps>
  </queue>
  <queue name="default">
    <minResources>100 mb,1vcores</minResources>
    <maxResources>6000 mb,2vcores</maxResources>
    <maxRunningApps>10</maxRunningApps>
    <weight>1.0</weight>
    <schedulingPolicy>fair</schedulingPolicy>
  </queue>
</queue>

  <user name="cdh5">
    <maxRunningApps>30</maxRunningApps>
  </user>
  <userMaxAppsDefault>5</userMaxAppsDefault>

  <queuePlacementPolicy>
    <rule name="specified" />
    <rule name="primaryGroup" create="false" />
    <rule name="default" />
  </queuePlacementPolicy>
</allocations>

cdh5使用者執行hadoop queue -showacls
Queue acls for user : cdh5

Queue Operations =====================
root 
root.cdh5 ADMINISTER_QUEUE,SUBMIT_APPLICATIONS
root.default 
root.ocnosql

問題:
提交任務的使用者需要在rm主機上也存在,否則提交任務會失敗:
WARN security.UserGroupInformation: No groups available for user

Used Resources: memory=mapreduce.map.memory.mb*num+mapreduce.reduce.memory.mb*num+yarn.app.mapreduce.am.resource.mb*num (mapred-site.xml)
cpu cores=mapreduce.map.cpu.vcores*num+mapreduce.reduce.cpu.vcores*num+yarn.app.mapreduce.am.resource.cpu-vcores*num
(注意引數: yarn.scheduler.increment-allocation-mb:記憶體規整化單位,預設是1024,這意味著,如果一個Container請求資源是1.5GB,則將被排程器規整化為ceiling(1.5 GB / 1GB) * 1G=2GB。
yarn.scheduler.minimum-allocation-mb 最小分配記憶體,如果以上記憶體設定小於這個值,會以這個值為準)

yarn.admin.acl 預設是*,需要修改為某個具體使用者(或者空?),否則aclAdministerApps配置不起作用。

<property>
    <name>yarn.acl.enable</name>
    <value>true</value>
    <description>Enable ACLs? Defaults to false.</description>
  </property>
  <property>
    <name>yarn.admin.acl</name>
    <value>cdh5</value>
    <description>ACL to set admins on the cluster. ACLs are of for comma-separated-usersspacecomma-separated-groups. Defaults to special value of * which means anyone. Special value of just space means no one has access</description>
  </property>

Updated by 楊 啟虎 , 更新於 19 分鐘 之前