分享

Hadoop-2.2.0中文文档:MapReduce 下一代 --公平调度器

本帖最后由 xioaxu790 于 2014-9-5 16:06 编辑
问题导读
1、如何让YARN在一个大集群中公平地共享资源?
2、可插入式的层级队列的内涵是什么?
3、分配文件的格式必须是什么。这个格式包含哪几种元素?


目的
此文档描述了 FairScheduler, Hadoop 的一个可插入式的调度器,允许 YARN 应用在一个大集群中公平地共享资源。


简介
        公平调度是一种分配资源给应用的方法,以致到最后,平均上所有应用获得相等的资源。  Hadoop NextGen 能够调度多种类型的资源。默认的, Fair Scheduler 仅以内存为基础作公平调度决策。可以用Ghodsi 等开发的 Dominant Resource Fairness 概念配置调度内存和CPU。仅有一个应用运行时,这个应用使用整个集群。别的应用提交了之后,空出来的资源就分配给新的应用,以便每个应用最终都能获得大致相等数量的资源。 不像默认的Hadoop 调度器把应用组成一个队列,这个让短的应用在合理的时间内完成,而长时间的应用则不会饥渴(?)。这也是一个合理的方式在多用户中分享一个集群的方式。最后,公平分享可以应用于应用优先级——优先级用于决定每个应用可以得到的资源部分的权重。

       调度器进一步会把应用组织到 “队列”中,并在这些队列间公平地分享资源。默认的,所有的用户分享一个叫做“默认”的单独的队列。如果一个应用特别地在一个容器资源请求中列出一个队列,请求就提交给那个队列。也有可能基于通过请求配置用户名字来分配队列。在每个队列中,一个调度政策用来在运行着的应用间共享资源。默认是基于内存的公平调度,但是FIFO和Dominant Resource Fairness的多资源也会被配置。队列会被组织在一个层级中,以指定的比例分享集群分配资源和权重配置。

       除了提供公平分享之外,Fair Scheduler 允许分配给队列最小的共享保证,对于确保确定的用户、组或生产应用总能获得充足的资源非常有用。当一个队列包含应用,它至少能获得最小的分享,但是当队列不需要它的全部保证的分享,超过的部分就会在别的运行中的应用中分配。当这些队列不包含应用时,这让调度器保证队列容量同时要有效地使用资源。

       Fair Scheduler 让所有的应用默认地运行,但是也有可能通过配置文件限制每个用户和每个队列的运行中的应用的数量。当一个用户必须要立即提交数百个应用,或如果同时运行太多应用还要提升性能,可能导致生成太多的中间数据或太多的上下文切换时,这非常有用。应用限制不会引起任何随后提交的应用失败,只会在调度器队列中等待直到一些用户的之前的应用执行完成。


可插入式的层级队列
       公平调度器支持层级队列。所有的队列继承自一个叫做“root”的队列。在典型的调度样式中,可用的资源分布在根队列的子队列中。然后,子队列以同样的方式分布资源到他们的子队列中。应用可能只被安排在左队列中。队列会被指定为别的队列的子队列,通过在公平调度器分配文件中把它们放到他们父队列的子元素中。
        一个队列的名字以其父队列的名字开始,以周期(?)作为分隔符。所以一个在根队列下的名叫“queue1”的队列,会被写为 "root.queue1", 在一个名叫"parent1"的一个名叫 "queue2" 的队列将会被写为 "root.parent1.queue2"。 当参考(?)队列,根部分是可选的,所以queue1可以仅写为 "queue1", queue2 仅写为 "parent1.queue2".

        还有,公平调度器允许为每个队列设置一个自定义的政策,允许用户能以任何他想要的方式使用队列资源。一个自定义的政策可以通过继承 org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.SchedulingPolicy 来创建。 FifoPolicy, FairSharePolicy (默认的), 和 DominantResourceFairnessPolicy 是内置的,随时等待使用。

        在原来的(MR1)Fair Scheduler 中的某些附件还没有被支持。在其中,在某些应用中,自定义政策管理优先级“推动”。


安装
要使用 Fair Scheduler ,首先在 yarn-site.xml 分配合适的调度器类:
  1. <property>
  2.   <name>yarn.resourcemanager.scheduler.class</name>
  3.   <value>org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.FairScheduler</value>
  4. </property>
复制代码


配置
自定义 Fair Scheduler 一般涉及修改两个文件。首先,调度器端选项可以通过在你的现存配置目录中的yarn-site.xml中添加配置属性来设置。其次,大多数情况下,用户会想要创建一个包含队列各自的权重和容量的分配文件列表。分配文件每10秒重载一次,允许动态修改。

属性可以放在 yarn-site.xml 中
yarn.scheduler.fair.allocation.file
分配(配置)文件的路径.一个分配文件是一个XML清单,描述了队列及其属性,还有默认的政策。这个文件必须是下一节中描述的XML格式。如果给定了一个相对路径,文件就会在classpath(一般包含Hadoop conf 目录)上被搜索。默认是 fair-scheduler.xml.

yarn.scheduler.fair.user-as-default-queue
无论是否用与分配相关联的用户名作为默认的队列名,事实上队列的名字并没有被指定。如果这被设置为 "false" 或是没有设置,所有的job共享一个默认的队列,叫做 "默认". 默认是 true.

yarn.scheduler.fair.preemption
是否使用预占有。注意 preemption 在当前版本中是实验性质的。默认是 false.

yarn.scheduler.fair.sizebasedweight
是否基于应用的规模分配共享给单独的应用,还是提供相同大小的共享给所有的应用,而不考虑他们的规模。若设置为true,将通过一个应用请求的总内存的自然对数除以2来给应用赋予权重。默认是2.

yarn.scheduler.fair.assignmultiple
是否允许在多个容器分配存在一个心跳。默认是false。

yarn.scheduler.fair.max.assign
如果多个分配是true,最大数量的容器将被分配一个心跳。默认是 -1, 代表没有限制。

yarn.scheduler.fair.locality.threshold.node
对于在特定节点上请求容器的应用,从上一个容器分配到等待另一个节点上的调度机会的数量。记为0-1的浮点数,是集群规模的比例,是向上传递的调度机会的数量。

yarn.scheduler.fair.locality.threshold.rack
对于在特定机架上请求容器的应用,从上一个容器分配到等待另一个节点上的调度机会的数量。记为0-1的浮点数,是集群规模的比例,是向上传递的调度机会的数量。默认值是-1,意思是不传递任何调度机会。

分配文件的格式
分配文件必须是 XML 格式。这个格式包含五种元素:
Queue 元素, 代表队列. 每个可能包含下面的属性:
  1. minResources: minimum resources the queue is entitled to, in the form "X mb, Y vcores". For the single-resource fairness policy, the vcores value is ignored. If a queue's minimum share is not satisfied, it will be offered available resources before any other queue under the same parent. Under the single-resource fairness policy, a queue is considered unsatisfied if its memory usage is below its minimum memory share. 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. If multiple queues are unsatisfied in this situation, resources go to the queue with the smallest ratio between relevant resource usage and minimum. Note that it is possible that a queue that is below its minimum may not immediately get up to its minimum when it submits an application, because already-running jobs may be using those resources.
  2. maxResources: maximum resources a queue is allowed, in the form "X mb, Y vcores". For the single-resource fairness policy, the vcores value is ignored. A queue will never be assigned a container that would put its aggregate usage over this limit.
  3. maxRunningApps: limit the number of apps from the queue to run at once
  4. weight: to share the cluster non-proportionally with other queues. Weights default to 1, and a queue with weight 2 should receive approximately twice as many resources as a queue with the default weight.
  5. schedulingPolicy: to set the scheduling policy of any queue. The allowed values are "fifo"/"fair"/"drf" or any class that extendsorg.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.SchedulingPolicy. Defaults to "fair". If "fifo", apps with earlier submit times are given preference for containers, but apps submitted later may run concurrently if there is leftover space on the cluster after satisfying the earlier app's requests.
  6. aclSubmitApps: a list of users that can submit apps to the queue. A (default) value of "*" means that any users can submit apps. A queue inherits the ACL of its parent, so if a queue2 descends from queue1, and user1 is in queue1's ACL, and user2 is in queue2's ACL, then both users may submit to queue2.
  7. minSharePreemptionTimeout: number of seconds the queue is under its minimum share before it will try to preempt containers to take resources from other queues.
复制代码

User 元素, 代表管理单独用户行为的设置。他们可以包含一个单独的属性: maxRunningApps, 指定用户的运行应用数量限制。
一个 userMaxAppsDefault 元素, 如果没有特别指定,设置了每个用户的默认运行应用限制。
一个 fairSharePreemptionTimeout 元素, 一个队列在尝试从其他队列抢占资源容器前,其公平分享下的秒数。
一个 defaultQueueSchedulingPolicy 元素, 为队列设置了默认的调度政策:如果在每个队列的schedulingPolicy 元素中指定就会被覆盖。默认是 "fair".
下面是分配文件的一个例子:
  1. <?xml version="1.0"?>
  2. <allocations>
  3.   <queue name="sample_queue">
  4.     <minResources>10000 mb,0vcores</minResources>
  5.     <maxResources>90000 mb,0vcores</maxResources>
  6.     <maxRunningApps>50</maxRunningApps>
  7.     <weight>2.0</weight>
  8.     <schedulingPolicy>fair</schedulingPolicy>
  9.     <queue name="sample_sub_queue">
  10.       <minResources>5000 mb,0vcores</minResources>
  11.     </queue>
  12.   </queue>
  13.   <user name="sample_user">
  14.     <maxRunningApps>30</maxRunningApps>
  15.   </user>
  16.   <userMaxAppsDefault>5</userMaxAppsDefault>
  17. </allocations>
复制代码
注意,由于对之前的 FairScheduler 的后向兼容, "queue" 元素可以被 "pool" 元素代替.


管理
公平调度器提供了对运行时管理的两种机制的支持:
通过编辑分配文件,可以修改最低共享、限制、权重、预占有时间差和队列调度政策。调度器会在知道此文件修改了之后10-15秒后会重载它。
当前应用、队列和公平分享可以通过 ResourceManager的 web 界面检查,地址是 http://ResourceManager URL/cluster/scheduler.
下面的每个队列的域可以在web界面上查看:
用过的资源 - 在队列内分配给容器的资源总和。
活着的应用的数量 - 队列中的至少接到一个容器的应用的数量。
待运行的应用的数量 - 队列中的还未接到任何容器的应用的数量。
最低资源 - 保证给一个队列的配置了的最低资源。
最大资源 - 允许给一个队列的配置了的最大资源。
公平分享 - 队列的公平分享资源。当别的队列不在使用的时候,队列可能会被分配超过他们的公平分享的资源。一个队列的资源消耗刚好等于或低于它的公平分享的话,它的容器永远不会预占有。
ResourceManager 为正常地展示关于每个应用的额外信息,web 界面包含应用的公平分享。



已有(1)人评论

跳转到指定楼层
hery 发表于 2014-9-6 13:46:18
不错的资料。。。。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

推荐上一条 /2 下一条