公平调度器案例
1. 需求
创建两个队列,分别是 test 和 codecat(以用户所属组命名)。期望实现以下效果:若用 户提交任务时指定队列,则任务提交到指定队列运行;若未指定队列,test 用户提交的任务 到 root.group.test 队列运行,codecat 提交的任务到 root.group.codecat 队列运行(注:group为用户所属组)
2. 配置多队列的公平调度器
公平调度器的配置涉及到两个文件,一个是 yarn-site.xml ,另一个是公平调度器队列分配文件 fair-scheduler.xml (文件名可自定义)。其中配置文件参考:https://hadoop.apache.org/docs/r3.1.3/hadoop-yarn/hadoop-yarn-site/FairScheduler.html,任务队列放置规则参考:https://blog.cloudera.com/untangling-apache-hadoop-yarn-part-4-fair-scheduler-queue-basics/
-
修改 yarn-site.xml 文件,加入以下参数 <property>
<name>yarn.resourcemanager.scheduler.class</name>
<value>org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.FairS
cheduler</value>
<description>配置使用公平调度器</description>
</property>
<property>
<name>yarn.scheduler.fair.allocation.file</name>
<value>/opt/module/hadoop-3.1.3/etc/hadoop/fair-scheduler.xml</value>
<description>指明公平调度器队列分配配置文件路径</description>
</property>
<property>
<name>yarn.scheduler.fair.preemption</name>
<value>false</value>
<description>禁止队列间资源抢占</description>
</property>
-
配置 fair-scheduler.xml <?xml version="1.0"?>
<allocations>
<queueMaxAMShareDefault>0.5</queueMaxAMShareDefault>
<queueMaxResourcesDefault>4096mb,4vcores</queueMaxResourcesDefault>
<queue name="test">
<minResources>2048mb,2vcores</minResources>
<maxResources>4096mb,4vcores</maxResources>
<maxRunningApps>4</maxRunningApps>
<maxAMShare>0.5</maxAMShare>
<weight>1.0</weight>
<schedulingPolicy>fair</schedulingPolicy>
</queue>
<queue name="codecat" type="parent">
<minResources>2048mb,2vcores</minResources>
<maxResources>4096mb,4vcores</maxResources>
<maxRunningApps>4</maxRunningApps>
<maxAMShare>0.5</maxAMShare>
<weight>1.0</weight>
<schedulingPolicy>fair</schedulingPolicy>
</queue>
<queuePlacementPolicy>
<rule name="specified" create="false"/>
<rule name="nestedUserQueue" create="true">
<rule name="primaryGroup" create="false"/>
</rule>
<rule name="reject" />
</queuePlacementPolicy>
</allocations>
-
分发配置并重启 Yarn 会出现3个队列 -
提交任务时指定队列 hadoop jar /opt/module/hadoop3.1.3/share/hadoop/mapreduce/hadoop-mapreduce-examples-3.1.3.jar pi -D mapreduce.job.queuename=root.test 1 1
-
提交任务时不指定队列,在codecat 用户提交 hadoop jar /opt/module/hadoop3.1.3/share/hadoop/mapreduce/hadoop-mapreduce-examples-3.1.3.jar pi -D 1 1
参考: https://www.bilibili.com/video/BV1Qp4y1n7EN?from=search&seid=10867430921318637499&spm_id_from=333.337.0.0
|