Administrator
Published on 2023-11-15 / 3 Visits
0

容量调度器

一、介绍

Capacity Scheduler,现在已经成了 Hadoop 中的默认调度器,其被设计成一个可拔插的调度程序,允许多个租户安全地共享一个大型集群,这样他们的应用程序就可以在分配容量的限制下及时地分配资源。其表现为,多个队列组成一个树状结构,根节点为 root 队列,这个树的叶子节点通过配置来被分配其应该占用 root 的多少资源。如果希望使用Capacity Scheduler,需要在yarn-site.xml文件中配置(其实默认值就是这个)

  <property>
    <name>yarn.resourcemanager.scheduler.class</name>
    <value>org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacityScheduler</value>
  </property>

二、基础配置

所有关于Capacity Scheduler使用的配置全都需要在capacity-scheduler.xml文件中配置,下面主要介绍下基础配置。

树状队列的基础配置

<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>

此配置代表,root 队列下有a,b,c三个子队列,a 队列有a1,a2两个子队列,b 队列有 b1,b2 两个子队列。

为每个叶子队列分配资源

yarn.scheduler.capacity..capacity一个节点的占其父节点的比例,float 类型表示,队列的实际使用可能超过此值来达到弹性的效果。
yarn.scheduler.capacity..maximum-capacity一个节点的最大资源所占父结点的比例,float 类型表示,表示可以使用超过基础资源的弹性情况。
yarn.scheduler.capacity..minimum-user-limit-percent每个用户对于此队列使用最低资源数量的保障。
yarn.scheduler.capacity..user-limit-factor第一个参数的倍数,表示每个用户可使用资源数量的上限。

控制队列行为

yarn.scheduler.capacity.maximum-applications / yarn.scheduler.capacity..maximum-applications队列中最多容纳运行的 app 数量,可以全局配置也可以指定队列配置。
yarn.scheduler.capacity..stateRUNNING,STOPPED两种状态,只有 RUNNING 状态才可以正常提交。
yarn.scheduler.capacity.root..acl_submit_applications指定哪些用户可以向此队列提交任务。
yarn.scheduler.capacity.root..acl_administer_queue指定哪些用户可以管理此队列中的任务。

三、高阶使用

抢占

Capacity Scheduler允许被借用资源的队列重新拿回属于自己的资源,使用时需要在 yarn-site.xml文件增加如下配置。

  <property>
    <description>Enable a set of periodic monitors (specified in
        yarn.resourcemanager.scheduler.monitor.policies) that affect the
        scheduler.</description>
    <name>yarn.resourcemanager.scheduler.monitor.enable</name>
    <value>false</value>
  </property>

  <property>
    <description>The list of SchedulingEditPolicy classes that interact with
        the scheduler. A particular module may be incompatible with the
        scheduler, other policies, or a configuration of either.</description>
    <name>yarn.resourcemanager.scheduler.monitor.policies</name>
    <value>org.apache.hadoop.yarn.server.resourcemanager.monitor.capacity.ProportionalCapacityPreemptionPolicy</value>
  </property>

预留资源

Capacity Scheduler允许在单个队列的闲置资源无法满足一个 container 的申请尺寸时,其会在当前节点上预留一个Container申请,等到节点有资源时优先满足预留,节点在满足此预留之前不能满足其它请求。使用此功能需要在 yarn-site.xml下增加如下配置。

  <property>
    <description>
    Flag to enable the ResourceManager reservation system.
    </description>
    <name>yarn.resourcemanager.reservation-system.enable</name>
    <value>false</value>
  </property>

  <property>
    <description>
    The Java class to use as the ResourceManager reservation system.
    By default, is set to
    org.apache.hadoop.yarn.server.resourcemanager.reservation.CapacityReservationSystem
    when using CapacityScheduler and is set to
    org.apache.hadoop.yarn.server.resourcemanager.reservation.FairReservationSystem
    when using FairScheduler.
    </description>
    <name>yarn.resourcemanager.reservation-system.class</name>
    <value></value>
  </property>

  <property>
    <description>
    The plan follower policy class name to use for the ResourceManager
    reservation system.
    By default, is set to
    org.apache.hadoop.yarn.server.resourcemanager.reservation.CapacitySchedulerPlanFollower
    is used when using CapacityScheduler, and is set to
    org.apache.hadoop.yarn.server.resourcemanager.reservation.FairSchedulerPlanFollower
    when using FairScheduler.
    </description>
    <name>yarn.resourcemanager.reservation-system.plan.follower</name>
    <value></value>
  </property>

  <property>
    <description>
    Step size of the reservation system in ms
    </description>
    <name>yarn.resourcemanager.reservation-system.planfollower.time-step</name>
    <value>1000</value>
  </property>

capacity-scheduler.xml需要配置的内容
image.png