有很多job向RM申请资源时,资源调度器会根据设置的规则决定把资源给谁。YARN中有以下资源调度器。
按先来后到顺序
多个FIFO队列,每个队列有最大资源分配限制。
1)修改capacity-scheduler.xml文件
<property> <name>yarn.scheduler.capacity.root.queues</name> <value>default,hive</value> <description> The queues at the this level (root is the root queue). </description> </property> <!--队列目标资源百分比,所有队列相加必须等于100--> <property> <name>yarn.scheduler.capacity.root.default.capacity</name> <value>40</value> </property> <property> <name>yarn.scheduler.capacity.root.hive.capacity</name> <value>60</value> </property> <!--hive队列最大资源百分比--> <property> <name>yarn.scheduler.capacity.root.hive.maximum-capacity</name> <value>100</value> </property> <!--单用户可用hive队列资源占比--> <property> <name>yarn.scheduler.capacity.root.hive.user-limit-factor</name> <value>1</value> </property> <!--hive队列状态(RUNNING或STOPPING)--> <property> <name>yarn.scheduler.capacity.root.hive.state</name> <value>RUNNING</value> </property> <!--hive队列允许哪些用户提交--> <property> <name>yarn.scheduler.capacity.root.hive.acl_submit_applications</name> <value>*</value> </property> <!--hive队列允许哪些用户管理--> <property> <name>yarn.scheduler.capacity.root.hive.acl_administer_queue</name> <value>*</value> </property>2)Driver类中把job提交到hive队列
configuration.set("mapred.job.queue.name", "hive");1)多个队列,每个队列将资源平均分配给所有job,所有job可并行运行。
2)每个作业可以设置最小资源值。公平调度器会保证分配最小资源。
3)公平调度器优先为缺额大的job分配资源。(调度器是一点点分配资源的,而不是一下分配的,某个job需要资源5%,它会从0%慢慢涨到5%,这段时间缺的资源叫作缺额)
4)公平调度器实现的是动态公平,不停调整缺额和超额。