YARN学习总结-第四节-YARN调度器

1.容量调度器

容量调度器被设计来运行Hadoop应用在一个共享的,多租户的操作友好的集群上,最大化集群吞吐量和利用率。CapacityScheduler通过一系列的约束保证集群资源不会被个别恶意应用独占。保证共享集群的用户能获得保证的资源。这些功能会通过队列(queue)来实现。

功能列表:

  • Hierarchical Queues:分层队列
  • Capacity Guarantees:容量保证,队列被分配容量网格的一个分数。
  • Security:安全,每个队列有一个访问控制列表(ACL)控制哪个用户可以提交应用到特定队列,同时提供安全保证,不允许查看或者修改别的用户的应用。
  • Elasticity:弹性,空闲的资源可以被分配到任何队列使其可以超出它的容量。
  • Multi-tenancy:多租户,提供综合限制去保护一个单应用,单用户,单队列不会压垮集群。
  • Operability:可操作性。

       运行时配置:队列的定义和属性,容量,ACLs可以在运行时改变。管理员可以通过安全的方式实现,最小化减少对用户的中断。同时提供一个控制台给用户或者管理员去查看当前系统中已经分配给各个队列的资源。管理员可以运行时添加附加的队列,但是不能运行时删除队列。

       Drain applications:管理员可以运行时停止队列,让已经存在队列里面的应用运行完成,保证没有新应用被提交。如果一个队列是STOPPED状态,新的应用不能被提交到这个队列或者这个队列的子队列。存在的应用会继续完成。

  • Resource-based Scheduling:应用可以指定比默认更高的资源请求。
  • Queue Mapping based on User or Group:允许用户基于用户或者组去映射一个作业到特定队列。
  • Priority Scheduling:可以给应用指定优先级,是一个整数,数字越大,表明优先级越高,当前支持的应用优先级为FIFO顺序策略。
  • Absolute Resource Configuration: 管理员可以提供绝对的资源到一个队列,代替之前的百分比值。
  • Dynamic  Auto-Creation and Management of Leaf Queues: 自动创建和管理叶子队列。

配置:

  • 设置ResourceManager使用CapacityScheduler

设置conf/yarn-site.yml

属性名:yarn.resourcemanager.scheduler.class

值:org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacityScheduler

  • 设置队列

设置capacity-scheduler.xml

容量调度器有个预定义的队列,名字是root,所有的队列都是root的子队列。更多的子队列可以被设置,通过配置

yarn.scheduler.capacity.root.queues,逗号分开的子队列即可。CapacityScheduler使用一个叫做队列路径的概念去配置层级队列。子队列不会直接从父队列继承属性,除非明确指明。

<property>
  <name>yarn.scheduler.capacity.root.queues</name>
  <value>a,b,c</value>
  <description>The queues at the this level (root is the root queue).
  </description>
</property>

<property>
  <name>yarn.scheduler.capacity.root.a.queues</name>
  <value>a1,a2</value>
  <description>The queues at the this level (root is the root queue).
  </description>
</property>

<property>
  <name>yarn.scheduler.capacity.root.b.queues</name>
  <value>b1,b2,b3</value>
  <description>The queues at the this level (root is the root queue).
  </description>
</property>
  • 队列属性

    Resource Allocation

yarn.scheduler.capacity.<queue-path>.capacity:使用浮点数的百分比或者绝对资源。在每一级,容量总和必须等于100。如果使用绝对容量,子队列的决对容量可以比父队列的容量小,队列里面的应用可以指定超出队列容量的资源,以期待可以利用空闲资源。

yarn.scheduler.capacity.<queue-path>.maximum-capacity:以百分比表示的最大队列容量或者绝对形式表示的队列最大容量。但是这会限制队列里应用的弹性伸缩。管理员需要确保绝对最大容量大于每个队列的绝对容量。如果设置这个值为-1,表示最大容量为100%。

yarn.scheduler.capacity.<queue-path>.minimum-user-limit-percent:一个整形值。

yarn.scheduler.capacity.<queue-path>.user-limit-factor:默认是浮点数float,值为1。

yarn.scheduler.capacity.<queue-path>.maximum-allocation-mb:每个队列能分配给各每个容器请求的最大内存。这个设置会覆盖集群配置,yarn.scheduler.maximum-allocation-vcores。这个值必须小于集群配置的值。

yarn.scheduler.capacity.<queue-path>.maximum-allocation-vcores:每个队列能分配给各每个容器请求的最大虚拟cpu核心。这个设置会覆盖集群配置,yarn.scheduler.maximum-allocation-vcores。这个值必须小于集群配置的值。

yarn.scheduler.capacity.<queue-path>.user-settings.<user-name>.weight:浮点数值,用户权重,默认为1.0。

Resource Allocation using Absolute Resources configuration

管理员可以通过指定绝对值形式的资源分配,而不是百分比。例如:memory=10240,vcores=12

Running and Pending Application Limits

yarn.scheduler.capacity.maximum-applications

yarn.scheduler.capacity.<queue-path>.maximum-applications

限制最大可以并发激活的Running and Pending的应用数。

yarn.scheduler.capacity.maximum-am-resource-percent

yarn.scheduler.capacity.<queue-path>.maximum-am-resource-percent

限制application master最大资源百分比,以此来控制并发激活的应用,默认是10%。

Queue Administration & Permissions

yarn.scheduler.capacity.<queue-path>.state:队列状态,枚举值,可以是RUNNING or STOPPED,如果队列状态是STOPPED,已经存在的应用会继续运行完成,其他的应用无法提交,如果是root队列,则集群无法提交应用。

yarn.scheduler.capacity.root.<queue-path>.acl_submit_applications:ACL控制谁可以提交应用到给定的队列,如果不指定,则从父队列继承。

yarn.scheduler.capacity.root.<queue-path>.acl_administer_queue:ACL控制谁可以管理特定队列上的应用。

Queue Mapping based on User or Group

yarn.scheduler.capacity.queue-mappings:映射单个用户或者用户组到一个队列。

Syntax:[ u or g ] : [ name ] : [ queue_name ] [ ,next_mappings. ] *

yarn.scheduler.capacity.queue-mappings-override.enable:布尔值,默认为false。

Queue lifetime for applications

yarn.scheduler.capacity.<queue-path>.maximum-application-lifetime:被提交到队列的应用的最大生命周期。任何小于等于0的值都被认为是关闭。这个设置对所有队列来说是个硬限制。任何超过生命周期的应用会被kill掉。用户可在提交上下文指定生命周期。但是如果用户配置的生命周期超过此值,会被覆盖。这个功能只能被配置到叶子队列。

yarn.scheduler.capacity.root.<queue-path>.default-application-lifetime:默认生命周期。如果用户没有指定生命周期,则此值会被应用。默认生命周期不能超过最大生命周期。这个功能只能被配置到叶子队列。

  • 设置应用优先级

优先级只工作在FIFO策略下,默认的排序策略是FIFO。默认优先级可以在集群级别设置或者队列级别设置。

集群级别优先级:

修改配置文件:capacity-scheduler.xml

yarn.cluster.max-application-priority

叶子队列级别优先级:

yarn.scheduler.capacity.root.<leaf-queue-path>.default-application-priority。

Note:当应用被移动到不同队列后,不能修改应用的优先级。

  • Capacity Scheduler container preemption

Capacity Scheduler 支持从队列到资源使用的容器的优先级。

需要在yarn-site.xml里面配置下列参数为enabled,以支持应用容器的优先级。

yarn.resourcemanager.scheduler.monitor.enable:允许周期性监控,这些监控,可以在yarn.resourcemanager.scheduler.monitor.policies中指定。

yarn.resourcemanager.scheduler.monitor.policies:列表形式的SchedulingEditPolicy类。默认的监控策略类是org.apache.hadoop.yarn.server.resourcemanager.monitor.capacity.ProportionalCapacityPreemptionPolicy,它是与CapacityScheduler兼容的。

如果有上述配置,可以继续在yarn-site.xml配置下列参数以支持控制容器的优先级。

yarn.resourcemanager.monitor.capacity.preemption.observe_only:默认值是false。如果配置为true,策略会运行,但是不影响集群。

yarn.resourcemanager.monitor.capacity.preemption.monitoring_interval:默认是3000,单位是毫秒。

yarn.resourcemanager.monitor.capacity.preemption.max_wait_before_kill:默认是15000,单位是毫秒。

yarn.resourcemanager.monitor.capacity.preemption.total_preemption_per_round:单个round下最大资源有线百分比,默认为0.1

yarn.resourcemanager.monitor.capacity.preemption.max_ignored_over_capacity:默认值为0.1

yarn.resourcemanager.monitor.capacity.preemption.natural_termination_factor:默认值为0.2

CapacityScheduler支持下列配置来控制已经提交到一个队列的应用

yarn.scheduler.capacity.<queue-path>.disable_preemption:默认值为false。

yarn.scheduler.capacity.<queue-path>.intra-queue-preemption.disable_preemption:这个属性只有在满足下列属性的时候才被应用:

yarn.resourcemanager.scheduler.monitor.enable to true

yarn.resourcemanager.scheduler.monitor.policiesto ProportionalCapacityPreemptionPolicy

yarn.resourcemanager.monitor.capacity.preemption.intra-queue-preemption.enabled to true

如果没有设置,则默认从父队列继承。

  • Reservation Properties

Reservation Administration & Permissions

CapacityScheduler支持下列参数控制Reservation的创建,删除,更新,列出。如果Reservation被开启了但是没有定义,任何用户都有权限可以执行此动作。

yarn.scheduler.capacity.root.<queue>.acl_administer_reservations:ACL控制谁可以管理指定的队列的保留资源。如果不指定,则对于这个属性的ACL不会从父队列继承。

yarn.scheduler.capacity.root.<queue>.acl_list_reservations:ACL控制谁可以列出指定队列的保留资源。如果不指定,则对于这个属性的ACL不会从父队列继承。

yarn.scheduler.capacity.root.<queue>.acl_submit_reservations:ACL控制谁可以提交保留资源到指定的队列。如果不指定,则对于这个属性的ACL不会从父队列继承。

  • 配置ReservationSystem

yarn.resourcemanager.reservation-system.enable:必须指定的参数。默认值为false。

yarn.resourcemanager.reservation-system.class:可选参数。默认值取决于调度器,如果是容量调度器,则为CapacityReservationSystem。

yarn.resourcemanager.reservation-system.plan.follower:可选参数。

yarn.resourcemanager.reservation-system.planfollower.time-step:可选参数。默认值为1000。

ReservationSystem可以被配置到任何队列,包括叶子队列。

yarn.scheduler.capacity.<queue-path>.reservable:必须指定的参数。表明队列的资源对于用户保留来说是可获得的。

yarn.scheduler.capacity.<queue-path>.reservation-agent:可选参数。

yarn.scheduler.capacity.<queue-path>.reservation-policy:可选参数。

yarn.scheduler.capacity.<queue-path>.reservation-window:可选参数。Long类型值,默认是一天。

yarn.scheduler.capacity.<queue-path>.instantaneous-max-capacity:可选参数,默认为1。

yarn.scheduler.capacity.<queue-path>.average-capacity:可选参数。

yarn.scheduler.capacity.<queue-path>.reservation-planner:可选参数。

yarn.scheduler.capacity.<queue-path>.reservation-enforcement-window:可选参数。默认为一小时。

  • Dynamic Auto-Create and Management of Leaf Queue

通过队列映射设置自动创建和管理叶子队列。

CapacityScheduler支持下面的参数开启自动创建队列

yarn.scheduler.capacity.<queue-path>.auto-create-child-queue.enabled:必须指定的参数。默认不开启自动创建和管理叶子队列。

yarn.scheduler.capacity.<queue-path>.auto-create-child-queue.management-policy:可选参数。

配置自动创建叶子队列

yarn.scheduler.capacity.<queue-path>.leaf-queue-template.capacity:必须提供的参数,目前,绝对形式的资源配置不支持自动创建叶子队列。

yarn.scheduler.capacity.<queue-path>.leaf-queue-template.<leaf-queue-property>:可选参数。

<property>
   <name>yarn.scheduler.capacity.root.parent1.auto-create-child-queue.enabled</name>
   <value>true</value>
 </property>
 <property>
    <name>yarn.scheduler.capacity.root.parent1.leaf-queue-template.capacity</name>
    <value>5</value>
 </property>
 <property>
    <name>yarn.scheduler.capacity.root.parent1.leaf-queue-template.maximum-capacity</name>
    <value>100</value>
 </property>
 <property>
    <name>yarn.scheduler.capacity.root.parent1.leaf-queue-template.user-limit-factor</name>
    <value>3.0</value>
 </property>
 <property>
    <name>yarn.scheduler.capacity.root.parent1.leaf-queue-template.ordering-policy</name>
    <value>fair</value>
 </property>
 <property>
    <name>yarn.scheduler.capacity.root.parent1.GPU.capacity</name>
    <value>50</value>
 </property>
 <property>
     <name>yarn.scheduler.capacity.root.parent1.accessible-node-labels</name>
     <value>GPU,SSD</value>
   </property>
 <property>
     <name>yarn.scheduler.capacity.root.parent1.leaf-queue-template.accessible-node-labels</name>
     <value>GPU</value>
  </property>
 <property>
    <name>yarn.scheduler.capacity.root.parent1.leaf-queue-template.accessible-node-labels.GPU.capacity</name>
    <value>5</value>
 </property>


 

2.公平调度器

  • 介绍

公平调度器(Fair Scheduling)是Hadoop另一个调度器,它是一个可以给所有应用平均地,公平的分配资源的方式。默认是基于内存分配,可以配置同时基于CPU和内存,是一个叫做主导资源公平(Dominant Resource Fairness)的概念,意思是哪个资源为主要公平分配参考。

举个例子:例如一个有100个CPU和10T内存的集群,应用A请求的每个container的资源为2个CPU和300G内存,应用B请求的每个container的资源为6个CPU和100G内存。A请求的资源中CPU占集群的2%,内存占3%,主导资源为内存。同理B的主导资源为CPU,占集群资源的6%。则B申请的资源就是A的两倍(6% vs 3%),那么公平调度下B分配到的container数量将是A的一半。默认情况下不使用DRF。

当有一个应用运行时,它使用全部资源,当有另外一个应用提交会,它会使用已经空闲的资源,所以到最后,每个应用粗略上使用了全部资源。同时,它支持应用优先级,可以对应用设置权重,决定每个应用可以获得的总的资源。

默认,所有用户使用一个默认的队列,名称为"default",如果应用特别指明了队列名称,则它会运行在特定队列。也有可能基于配置文件中的用户名去分配队列。队列内部会使用一个调度策略,默认是基于内存的共享,不是FIFO,但是可以配置多资源。

公平调度器默认让所有应用运行,不过可以通过配置文件设置每个用户和每个队列能运行的应用。

  • 带可插拔策略的层级队列

公平调度器也支持层级队列,默认的队列名称为root,可以指定子队列,例如:"root.queue1","root.parent1.queue2",应用的时候可以是"queue1","parent1.queue2",这个和容量调度器不一样,容量调度器只需要指定最后的叶子队列名称即可。

用户可以指定调度器使用的调度策略,例如:FifoPolicy,FairSharePolicy,DominantResourceFairnessPolicy,这些都是内置的,可以很容器替换。

  • 自动放置应用到队列
  • 设置公平队列

修改配置文件:yarn-site.xml

<property>
  <name>yarn.resourcemanager.scheduler.class</name>
  <value>org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.FairScheduler</value>
</property>
  • 配置

一般,定义公平调度器,通过两个文件,一个是集群范围内的,yarn-site.xml,另一个是用户自己创建的分配文件。分配文件每10秒重载一次。

yarn.scheduler.fair.allocation.file:分配文件是一个xml格式的文件,描述了队列和他们的属性,以及默认策略。默认是fair-scheduler.xml

yarn.scheduler.fair.user-as-default-queue:如果队列名没有指定,是否根据用户名去分配队列。如果设置为false或者没有设置,所有的作业会被调度到名称为"default"的队列,默认值是true。如果在分配文件中指定了放置策略,则这个属性被忽略。

yarn.scheduler.fair.preemption:是否允许抢占,默认为false。

yarn.scheduler.fair.preemption.cluster-utilizatioin-threshold:默认为0.3f。

yarn.scheduler.fair.sizebasedweigh:是否基于应用的大小分配资源而不是给所有的应用提供等价共享。如果指定了,则按照1的自然对数加上应用请求的总内存大小然后除以2的自然对数计算应用的权重。

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

yarn.scheduler.fair.dynamic.max.assign:如果允许在一个心跳,分配多个容器,则需要动态计算在一个心跳可以被分配的资源数量。默认为节点未分配资源的一半。

yarn.scheduler.fair.max.assign:默认为-1,意思是不限制。

yarn.scheduler.fair.locality.threshold.node:默认值为-1.0

yarn.scheduler.fair.locality.threshold.rack:

yarn.scheduler.fair.allow-undeclared-pools:默认为true

yarn.scheduler.fair.update-interval-ms:默认为500ms,执行锁定调度器,重新计算公平共享,重新计算需求,检查是否需要抢占的时间间隔。

yarn.resource-types.memory-mb.increment-allocation: 如果你请求的资源不是memory-mb.increment-allocation的倍数,则会四舍五入到接近增长值。默认是1024MB。

yarn.resource-types.vcores.increment-allocation:默认值为1.

yarn.resource-types.<resource>.increment-allocation:自定义资源的增长。

yarn.scheduler.increment-allocation-mb:废弃。

yarn.scheduler.increment-allocation-vcores:废弃。

  • 分配文件格式

分配文件必须是xml格式,格式包含五种类型的元素。

Queue elements:为了向后兼容,"queue"元素可以被替换为"pool"元素。表示队列,队列元素包含一个type属性,当设置为'parent',表示父队列,没有子队列。

    minResources:队列的最小资源。格式为:"X mb,Y vcores"。如果一个队列的资源不满足,则会从同样的父队列的其他兄弟队列获得资源。

    maxResources: 队列的最大资源。可以是绝对形式的值,也可以是百分比。一个应用不会被分配超过这个限制的资源。

    maxChildResource:一个临时子队列被分配的最大资源。

    maxRunningApps:队列一次可以运行的最大应用。

    maxAMShare:只可以被指定到叶子队列。Application Master可以分配到的资源。

    weight:设置队列的权重。

 schedulingPolicy:设置队列的调度策略。允许的值为:fifo/fair/drf或者任何扩展了org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.SchedulingPolicy类的实现。默认是fair。

     aclSubmitApps: 一个用户或者组的列表,表示可以提交应用到队列。

     aclAdministerApps: 一个用户或者组的列表,表示可以管理队列的应用。

     minSharePreemptionTimeout:一个应用去抢占容器的最小秒数。

     fairSharePreemptionTimeout:

     fairSharePreemptionThreshold:一个队列的公平共享抢占阈值。

     allowPreemptionFrom:决定是否允许调度器从一个队列抢占资源。

     reservation:设置ReservationSystem

User elements: 针对特定用户设置管控行为,可以是最大运行的应用。

A userMaxAppsDefault element: 如果不另行指定限制的默认用户最大apps数目。

A defaultFairSharePreemptionTimeout element: 默认如果在指定时间内未获得平等的资源的一半,则开始抢占。

A defaultMinSharePreemptionTimeout element:默认如果在指定时间内未获得最小的资源保障,则开始抢占。

A defaultFairSharePreemptionThreshold element:默认平等资源比例配置,默认值为0.5f。

A queueMaxAppsDefault element:队列默认最大应用数目。

A queueMaxAMShareDefault element:队列最大默认Application Master。

A defaultQueueSchedullingPolicy element:队列的默认调度策略。如果不设置,则为"fair"。

A reservation-agent element:  

A reservation-planner element

A queuePlacementPolicy element:队列放置策略,包含一些列的规则元素告诉调度器如何放置进入的应用到队列中。规则会被顺序应用。规则可以带参数,所有的规则接受"create"参数,表示规则是否可以创建队列。"create"默认是true。规则会依次应用,最后的规则必须是不会继续的规则。合法的规则如下:

specified:应用被放置到应用请求的队列中去,如果没有指定,继续匹配,如果应用指明一个队列以周期开头或者结尾,例如".q1","q1."则会被拒绝。

user:应用按照用户名去放置,例如:first.last会被替换成first_dot_last。

primaryGroup:应用按照用户主组名去放置。例如:one.two会被替换成one_dot_two。

secondaryGroupExistingQueue:应用按照用户第二主组名去放置。

nestedUserQueue:nestedUserQueue只有在返回一个parent queue的时候才能被应用。

default:应用被放置到default规则指定的队列中,如果没有指定,则放置到"root.default"队列中。

reject:应用被拒绝。

<?xml version="1.0"?>
<allocations>
  <queue name="sample_queue">
    <minResources>10000 mb,0vcores</minResources>
    <maxResources>90000 mb,0vcores</maxResources>
    <maxRunningApps>50</maxRunningApps>
    <maxAMShare>0.1</maxAMShare>
    <weight>2.0</weight>
    <schedulingPolicy>fair</schedulingPolicy>
    <queue name="sample_sub_queue">
      <aclSubmitApps>charlie</aclSubmitApps>
      <minResources>5000 mb,0vcores</minResources>
    </queue>
    <queue name="sample_reservable_queue">
      <reservation></reservation>
    </queue>
  </queue>

  <queueMaxAMShareDefault>0.5</queueMaxAMShareDefault>
  <queueMaxResourcesDefault>40000 mb,0vcores</queueMaxResourcesDefault>

  <!-- Queue 'secondary_group_queue' is a parent queue and may have
       user queues under it -->
  <queue name="secondary_group_queue" type="parent">
  <weight>3.0</weight>
  <maxChildResources>4096 mb,4vcores</maxChildResources>
  </queue>

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

  <queuePlacementPolicy>
    <rule name="specified" />
    <rule name="primaryGroup" create="false" />
    <rule name="nestedUserQueue">
        <rule name="secondaryGroupExistingQueue" create="false" />
    </rule>
    <rule name="default" queue="sample_queue"/>
  </queuePlacementPolicy>
</allocations>
  • 队列访问控制

"root"队列默认ACL为"*",即允许所有用户和组提交和杀死应用。

  • 保留访问控制

允许管理员设置谁可以给队列设置保留。当前支持更新和删除保留。任何人可以更新、删除、列出自己的保留。

配置保留系统

公平调度器允许提前设置保留,用户可以在提交的时候设置保留ID以使用保留资源。还可以配置如下参数。

yarn.resourcemanager.reservation-system.enable:默认值为false。

yarn.resourcemanager.reservation-system.class:保留系统的实现类。根据调度器决定,如果选择公平调度器,则为FairReservationSystem。

yarn.resourcemanager.reservation-system.plan.follower:FairSchedulerPlanFollower。

yarn.resourcemanager.reservation-system.planfollower.time-step:PlanFollower timer。

管理公平调度器

可以通过编辑分配文件在运行时修改最小共享,限制,权重,抢占超时,队列调度策略。如果问价发生变化,调度器会在10-15秒重载配置文件。

通过web ui监控

可以通过web ui查看当前的应用,队列,公平共享。一般会看到如下字段,Used Resources, Num Active Applications,Num Pending Applications,Min Resources(配置的最下保证资源),Max Resource,Instantaneous Fair Share,Steady Fair Share。

  • 在队列间移动应用

公平调度器允许移动一个运行的应用到不同的队列。

用法:yarn application -movetoqueue appID -queue targetQueueName

  • Dump Fair Scheduler state

可以周期性dump公平调度器的state,默认是关闭的。管理员可以通过设置

org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.FairScheduler.statedump 日志级别为DEBUG

默认公平调度器的日志会输出到资源管理器的日志文件,可能体积较大,可以配置log4j.properties去dump到单独的文件。

猜你喜欢

转载自blog.csdn.net/qq_20995587/article/details/81977558