文章目录
1.yarn的资源调度方式及生产配置
1.1 FIFO Scheduler 先进先出
1.2 Capacity Scheduler 计算
而对于Capacity调度器,
有一个专门的队列用来运行小任务,
但是为小任务专门设置一个队列会预先占用一定的集群资源,
这就导致大任务的执行时间会落后于使用FIFO调度器时的时间。
1.3 FairScheduler 公平 生产
在Fair调度器中,
我们不需要预先占用一定的系统资源,
Fair调度器会为所有运行的job动态的调整系统资源。
如下图所示
当第一个大job提交时,只有这一个job在运行,此时它获得了所有集群资源;
当第二个小任务提交后,Fair调度器会分配一半资源给这个小任
务,让这两个任务公平的共享集群资源。
需要注意的是,在下图Fair调度器中,从第二个任务提交到获得资源会有一定的延迟,因为它需要等待第一个任务释放占用的
Container。小任务执行完成之后也会释放自己占用的资源,
大任务又获得了全部的系统资源。
最终的效果就是Fair调度器即得到了高
的资源利用率又能保证小任务及时完成。
1.4 三种调度器的区别
fifo: 单队列 先进先出 同一时间只有一个任务运行
capacity-scheduler :默认容量调度 多队列 每一个队列同时只能由一个任务运行 并发度=队列的个数。
fair-scheduler:多队列,每一个队列同一时间可以有多个任务运行。并发度 》= 队列个数。
总结: hadoop 2.9.1版本默认是capacity-scheduler调度器(其他版本自行去官网查看),生产一般使用fair-scheduler调度器。
1.5 如何配置调度器
(1) 进入 $HADOOP_HOME/etc/hadoop/yarn-site.xml
<property>
<name>yarn.resourcemanager.scheduler.class</name>
<value>org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.FairScheduler</value>
<!-- <value>org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacityScheduler</value> -->
<description> The class to use as the resource scheduler.默认是CapacityScheduler</description>
</property>
(2)如果使用默认的CapacityScheduler调度器,修改$HADOOP_HOME/etc/hadoop/capacity-scheduler.xml
# 生产很少用,理解就好
# 现需要配置一个队列树资源
a.父队列root,有两个队列prd,dev,两个队列分配占root队列资源的70%,30%
b.子队列dev,又有2个叶子队列eng,science,两个队列分配占dev队列资源的50%,50%
root
|---prd 70%
|---dev 30%
|---eng 50%
|---science 50%
<property>
<name>yarn.scheduler.capacity.root.queues</name>
<value>prd,dev</value>
<description>The queues at the this level (root is the root queue).
</description>
</property>
<property>
<name>yarn.scheduler.capacity.root.dev.queues</name>
<value>eng,science</value>
<description>The queues at the this level (root is the root queue).
</description>
</property>
<!-- prd 队列配置 -->
<property>
<name>yarn.scheduler.capacity.prd.capacity</name>
<value>70</value>
<description>prd占整个资源的70%
</description>
</property>
<property>
<name>yarn.scheduler.capacity.prd.user-limit-factor</name>
<value>30</value>
<description>某个用户只能独暂队列prd的资源的30%
</description>
</property>
<!-- dev 队列配置 -->
<property>
<name>yarn.scheduler.capacity.dev.capacity</name>
<value>30</value>
<description>dev队列占整个资源的30%
</description>
</property>
<property>
<name>yarn.scheduler.capacity.dev.maximum-capacity</name>
<value>50</value>
<description>dev队列的弹性设置,最大是占用集群50%资源(其他队列资源空闲时,dev借用其他队列的资源)
</description>
</property>
<property>
<name>yarn.scheduler.capacity.dev.eng.capacity</name>
<value>50</value>
<description>dev子队列eng占dev队列整个资源的50%
</description>
</property>
<property>
<name>yarn.scheduler.capacity.dev.science.capacity</name>
<value>50</value>
<description>dev子队列science占dev队列整个资源的50%
</description>
</property>
(3)生产使用FairScheduler调度器,修改$HADOOP_HOME/etc/hadoop/fair-scheduler.xml
<?xml version="1.0"?>
<allocations>
<queue name="root">
<minResources>2048 mb,1 vcores</minResources>
<maxResources>95% memory,95% cpu</maxResources>
<!--<maxChildResources>5% memory,5% cpu</maxChildResources>-->
<maxRunningApps>200</maxRunningApps>
<maxAMShare>1.0f</maxAMShare>
<weight>1</weight>
<schedulingPolicy>fair</schedulingPolicy>
<queue name="flink">
<minResources>1024 mb,1 vcores</minResources>
<maxResources>19456 mb,22 vcores</maxResources>
<maxRunningApps>50</maxRunningApps>
<maxAMShare>1.0f</maxAMShare>
<weight>4</weight>
<!--
<allowPreemptionFrom>true</allowPreemptionFrom>
<fairSharePreemptionThreshold>0.7f</fairSharePreemptionThreshold>
<fairSharePreemptionTimeout>60</fairSharePreemptionTimeout>
<minSharePreemptionTimeout>60</minSharePreemptionTimeout>
-->
</queue>
<queue name="root">
<minResources>2048 mb,1 vcores</minResources>
<maxResources>70% memory,70% cpu</maxResources>
<maxRunningApps>100</maxRunningApps>
<maxAMShare>1.0f</maxAMShare>
<weight>4</weight>
<!--
<allowPreemptionFrom>true</allowPreemptionFrom>
<fairSharePreemptionThreshold>0.7f</fairSharePreemptionThreshold>
<fairSharePreemptionTimeout>60</fairSharePreemptionTimeout>
<minSharePreemptionTimeout>60</minSharePreemptionTimeout>
-->
</queue>
<queue name="oozie">
<minResources>1024 mb,1 vcores</minResources>
<maxResources>15% memory,15% cpu</maxResources>
<maxRunningApps>15</maxRunningApps>
<maxAMShare>0.8f</maxAMShare>
<weight>3</weight>
</queue>
<queue name="spark">
<minResources>1024 mb,1 vcores</minResources>
<maxResources>2049 mb,3 vcores</maxResources>
<maxRunningApps>3</maxRunningApps>
<maxAMShare>0.9f</maxAMShare>
<weight>2</weight>
</queue>
<queue name="default">
<minResources>0% memory,0% cpu</minResources>
<maxResources>0.5% memory,0.5% cpu</maxResources>
<maxRunningApps>1</maxRunningApps>
<maxAMShare>0.7f</maxAMShare>
<weight>1</weight>
</queue>
</queue>
</allocations>
标签解释:
<queue name="root"> </queue> : 队列名 上述一个root父队列下有flink、root、oozie、spark、default五个子队列
<minResources>2048 mb,1 vcores</minResources> :队列有权获得的最小资源
<maxResources>95% memory,95% cpu</maxResources> : 分配队列的最大资源,注意可以写具体值,也可写百分比
<maxRunningApps>200</maxRunningApps> : 限制队列中能够并行运行应用的最大数量
<maxAMShare>1.0f</maxAMShare> : 限制队列用于运行Application Master的资源比例。这个属性只能用于叶子队列。比如,如果设置为1.0f,那么在这个队列的AMs可以占用100%的内存和CPU的公平共享。这个值为-1.0f将会禁用该特性并且amShare不会进行校验。默认值是0.5f。 此值越大,所获得内存和cpu的占比越大。
<weight>1</weight> :与其他队列不成比例地共享群集。权重默认为1,权重为2的队列应该获得的资源大约是具有默认权重的队列的两倍。 此值越大,改队列获得资源越多.改值和队列的Instantaneous Fair Share(瞬时公平份额)有关,在后面会讲解到.
<schedulingPolicy>fair</schedulingPolicy>:设置任意队列的调度策略
更多配置详解,打开参考资料文章或参考官网
http://hadoop.apache.org/docs/stable/hadoop-yarn/hadoop-yarn-site/FairScheduler.html
2.对公平调度器的配置资源抢占的配置
(1)进入$HADOOP_HOME/etc/hadoop/yarn-site.xml,打开资源抢占,
还有其他配置参考https://blog.csdn.net/qq_38924171/article/details/100568046
<property>
<name>yarn.scheduler.fair.preemption</name>
<value>true</value>
<description>默认false</description>
</property>
<property>
<name>yarn.scheduler.fair.preemption.cluster-utilization-threshold</name>
<value>0.7f</value>
<description>抢占后的利用率阈值。利用率计算为所有资源中使用量与容量的最大比率。默认为0.8f。</description>
</property>
(2)使用FairScheduler调度器,修改$HADOOP_HOME/etc/hadoop/fair-scheduler.xml
<?xml version="1.0"?>
<allocations>
<queue name="root">
<minResources>2048 mb,1 vcores</minResources>
<maxResources>100% memory,100% cpu</maxResources>
<maxChildResources>100% memory,100% cpu</maxChildResources>
<maxRunningApps>100</maxRunningApps>
<maxAMShare>1.0f</maxAMShare>
<weight>1</weight>
<!--确定是否允许调度程序从队列中抢占资源。默认值为true。如果队列将此属性设置为false,则此属性将递归应用于所有子队列。 -->
<allowPreemptionFrom>true</allowPreemptionFrom>
<!--队列的公平共享抢占阈值。如果队列在没有收到fairSharePreemptionThreshold * fairShare资源的情况下等待fairSharePreemptionTimeout,则允许抢占容器以从其他队列获取资源 -->
<fairSharePreemptionThreshold>0.7f</fairSharePreemptionThreshold>
<!--队列在尝试抢占容器以从其他队列中获取资源之前,队列处于其公平共享阈值之下的秒数 -->
<fairSharePreemptionTimeout>60</fairSharePreemptionTimeout>
<!--队列在尝试抢占容器以从其他队列获取资源之前,队列在其最小份额之下的秒数 -->
<minSharePreemptionTimeout>60</minSharePreemptionTimeout>
<!--设置任意队列的调度策略 允许的值为“fifo”/“fair”/“drf”-->
<schedulingPolicy>fair</schedulingPolicy>
<queue name="root">
<minResources>2048 mb,1 vcores</minResources>
<!--Max Capacity是95%,SteadyFairShare是45% -->
<maxResources>95% memory,95% cpu</maxResources>
<maxRunningApps>25</maxRunningApps>
<!--默认0.5f, 队列所有运行中APP的AM资源总和超过了(总内存 * 0.5),会导致APP阻塞。 -->
<maxAMShare>1.0f</maxAMShare>
<!--Instanstaneous Fair Share权重最大,root队列将空闲队列的default的资源5%全拿过来了 -->
<weight>4</weight>
</queue>
<queue name="oozie">
<minResources>1024 mb,1 vcores</minResources>
<maxResources>30% memory,30% cpu</maxResources>
<maxRunningApps>10</maxRunningApps>
<maxAMShare>1.0f</maxAMShare>
<weight>3</weight>
</queue>
<queue name="spark">
<minResources>1024 mb,1 vcores</minResources>
<maxResources>20% memory,20% cpu</maxResources>
<maxRunningApps>6</maxRunningApps>
<maxAMShare>1.0f</maxAMShare>
<weight>2</weight>
</queue>
<queue name="default">
<minResources>1% memory,1% cpu</minResources>
<maxResources>5% memory,5% cpu</maxResources>
<maxRunningApps>1</maxRunningApps>
<maxAMShare>0.1f</maxAMShare>
<weight>1</weight>
</queue>
</queue>
</allocations>
3. 使用公平调度器后,yarn web界面Scheduler的理解
3.1 上述公平调度器配置后,yarn 队列的层级结构
一个root父队列下有flink、root、oozie、spark、default五个子队列
3.2 各个队列的资源分配情况
假设目前yarn中的Memory Total为200G,VCores Total为110,分析flink队列的资源情况
1.flink子队列的配置
<maxResources>19456 mb,22 vcores</maxResources>,可以看出和图中一样
2.oozie子队列的配置
<maxResources>15% memory,15% cpu</maxResources>
200G*15%=30G=30720
110*15%=16.5 vcore 图片中显示的是 16 vcore
3.root子队列的配置
<maxResources>70% memory,70% cpu</maxResources>
注意可以使用固定配置和比例配置
200G*70%=140G=143360M
110*70%=77 vcore
3.3 使用公平调度器后,yarn web界面Schedule理解
解释Steady Fair Share,Instantaneous Fair Share,UsedUsed (over fair share) ,Max Capacit 的分配与理解
先看看官方的翻译:
Instantaneous Fair Share - 队列的瞬时公平份额资源。这些资源仅考虑活动队列(具有正在运行的应用程序的队列),并用于调度决策。当其他队列不使用队列时,可以为队列分配超出其共享的资源。资源消耗等于或低于其瞬时公平份额的队列将永远不会抢占其容器。
Steady Fair Share - 队列稳定的公平份额资源。这些资源考虑所有队列,无论它们是否处于活动状态(已运行应用程序)。这样,计算就不会很频繁,而且仅在配置或容量发生变化时才会更改。它们旨在提供用户可以预期的资源可见性,从而显示在Web UI中
上面说的云里雾里,下图是对公平调度器的配置资源抢占的结果,我自己的理解:
**Steady Fair Share: 稳定公平份额(静态),是一个在yarn启动的时候就已经根据minShare、maxShare和weight确定的一个固定值。 简单来说是 初始分配的比例,给每个队列分配多少就是多少,不变的.
**Instantaneous Fair Share: 瞬时公平份额(动态)
首先,<weight>的含义是与其他队列不成比例地共享群集。权重默认为1,权重为2的队列应该获得的资源大约是具有默认权重的队列的两倍。 此值越大,改队列获得资源越多。
其次,root的<weight> 为4,default的<weight>为1,root的Instanstaneous Fair Share权重最大,root队列将空闲队列的default队列的资源(5%)全拿过来了,如果default队列有应用提交,root队列拿过来的资源会交还给deault对了,所以叫瞬时公平份额,这是随时需要还的资源.
**UsedUsed (over fair share) :
yarn队列中开启了抢占,其他队列的资源有空闲的时候,会出现任务资源申请超过了Steady+Instantaneous资源,此时队列就会抢占其他队列的资源了.
**Max Capacit: <maxResources>50% memory,50% cpu</maxResources> 分配的内存,cpu是多少,就能够看到改队列最大容量.