Hadoop计算能力调度器应用和配置

释放双眼,带上耳机,听听看~!

需求

公司里有两个部门,一个叫hive,一个叫pig,这两个部门都需要使用公司里的hadoop集群。于是问题来了,因为hadoop默认是FIFO调度的,谁先提交任务,谁先被处理,于是hive部门很担心pig这个部门提交一个耗时的任务,影响了hive的业务,hive希望可以和pig在高峰期时,平均使用整个集群的计算容量,互不影响。

思路

hadoop的默认调度器是FIFO,但是也有计算容量调度器,这个调度器可以解决上述问题。可以在hadoop里配置三个队列,一个是default,一个是hive,一个是pig。他们的计算容量分别是30%,40%,30%.这样hive和pig这两个部门,分为使用hive和pig两个队列,其中default作为其他部门或者临时使用。但是,如果hive部门和pig部门又希望,在平常时,没有人用集群的时候,hive或者部门可以使用100%的计算容量。

解决方法

修改hadoop的配置文件mapred-site.xml:


1
2
1<property> <name>mapred.jobtracker.taskScheduler</name> <value>org.apache.hadoop.mapred.CapacityTaskScheduler</value> </property> <property> <name>mapred.queue.names</name> <value>default,hive,pig</value> </property>
2

 

在capacity-scheduler.xml文件中填写如下内容:


1
2
1<property> <name>mapred.capacity-scheduler.queue.hive.capacity</name> <value>40</value> <description>Percentage of the number of slots in the cluster that are to be available for jobs in this queue. </description> </property> <property> <name>mapred.capacity-scheduler.queue.hive.maximum-capacity</name> <value>-1</value> <description> </description> </property> <property> <name>mapred.capacity-scheduler.queue.hive.supports-priority</name> <value>true</value> <description></description> </property> <property> <name>mapred.capacity-scheduler.queue.hive.minimum-user-limit-percent</name> <value>100</value> <description> </description> </property> <property> <name>mapred.capacity-scheduler.queue.hive.user-limit-factor</name> <value>3</value> <description></description> </property> <property> <name>mapred.capacity-scheduler.queue.hive.maximum-initialized-active-tasks</name> <value>200000</value> <description></description> </property> <property> <name>mapred.capacity-scheduler.queue.hive.maximum-initialized-active-tasks-per-user</name> <value>100000</value> <description></description> </property> <property> <name>mapred.capacity-scheduler.queue.hive.init-accept-jobs-factor</name> <value>10</value> <description></description> </property> <!-- pig --> <property> <name>mapred.capacity-scheduler.queue.pig.capacity</name> <value>30</value> <description></description> </property> <property> <name>mapred.capacity-scheduler.queue.pig.maximum-capacity</name> <value>-1</value> <description></description> </property> <property> <name>mapred.capacity-scheduler.queue.pig.supports-priority</name> <value>true</value> <description>If true, priorities of jobs will be taken into account in scheduling decisions. </description> </property> <property> <name>mapred.capacity-scheduler.queue.pig.minimum-user-limit-percent</name> <value>100</value> <description></description> </property> <property> <name>mapred.capacity-scheduler.queue.pig.user-limit-factor</name> <value>4</value> <description>The multiple of the queue capacity which can be configured to allow a single user to acquire more slots. </description> </property> <property> <name>mapred.capacity-scheduler.queue.pig.maximum-initialized-active-tasks</name> <value>200000</value> <description></description> </property> <property> <name>mapred.capacity-scheduler.queue.pig.maximum-initialized-active-tasks-per-user</name> <value>100000</value> <description></description> </property> <property> <name>mapred.capacity-scheduler.queue.pig.init-accept-jobs-factor</name> <value>10</value> <description></description> </property> <!-- default --> <property> <name>mapred.capacity-scheduler.queue.default.capacity</name> <value>30</value> <description></description> </property> <property> <name>mapred.capacity-scheduler.queue.default.maximum-capacity</name> <value>-1</value> <description></description> </property> <property> <name>mapred.capacity-scheduler.queue.default.supports-priority</name> <value>true</value> <description></description> </property> <property> <name>mapred.capacity-scheduler.queue.default.minimum-user-limit-percent</name> <value>100</value> <description></description> </property> <property> <name>mapred.capacity-scheduler.queue.default.user-limit-factor</name> <value>4</value> <description></description> </property> <property> <name>mapred.capacity-scheduler.queue.default.maximum-initialized-active-tasks</name> <value>200000</value> <description></description> </property> <property> <name>mapred.capacity-scheduler.queue.default.maximum-initialized-active-tasks-per-user</name> <value>100000</value> <description></description> </property> <property> <name>mapred.capacity-scheduler.queue.default.init-accept-jobs-factor</name> <value>10</value> <description></description> </property>
2

这里配置了三个队列,分别是hive,pig,default,hive的容量是40%,由属性mapred.capacity-scheduler.queue.hive.capacity决定,其他队列的容量同理可得。

需要配置hive,pig,default可以抢占整个集群的资源,由属性mapred.capacity-scheduler.queue.hive.user-limit-factor绝对,hive队列这个值是3,所以用户可以使用的资源限量是40% * 3 =120%,所有有效计算容量是集群的100%.其他队列的最大集群计算容量同理可得。

 

如何使用该队列

mapreduce:在Job的代码中,设置Job属于的队列,例如hive:


1
2
1conf.setQueueName("hive");
2

hive:在执行hive任务时,设置hive属于的队列,例如pig:


1
2
1set mapred.job.queue.name=pig;
2

 

动态更新集群队列和容量

生产环境中,队列及其容量的修改在现实中是不可避免的,而每次修改,需要重启集群,这个代价很高,如果修改队列及其容量的配置不重启呢:

1.在主节点上根据具体需求,修改好mapred-site.xml和capacity-scheduler.xml

2.把配置同步到所有节点上

3.使用hadoop用户执行命令:hadoop mradmin -refreshQueues

这样就可以动态修改集群的队列及其容量配置,不需要重启了,刷新mapreduce的web管理控制台可以看到结果。

注意:如果配置没有同步到所有的节点,一些队列会无法启用。

最后拷贝
capacity-scheduler
的jar包到hadoop安装路径的lib目录下:

  1. cp contrib/capacity-scheduler/hadoop-capacity-scheduler-0.20.203.0.jar ./lib/  

    重启jobtracker,搞定!

    附注:

*        capacity-scheduler*的一个小缺陷:假设任务A(任务A指定使用队列1:目前状态–忙),任务B(任务B指定使用队列2:目前状态–空闲),capacity-scheduler的漕位抢占机制是将mapred任务A分配到队列2,假设任务A分配之后队列2又接收到了任务B,则任务A的优先级低于任务B,则调度器将优先分配队列2的槽位给任务B,从而导致任务A分配到的资源很少,且即使一段时间后队列1空闲,也无法将任务A重新分配到队列1

给TA打赏
共{{data.count}}人
人已打赏
安全运维

基于spring boot和mongodb打造一套完整的权限架构(三)【抽象实现类和swagger的实现】

2021-12-11 11:36:11

安全运维

Ubuntu上NFS的安装配置

2021-12-19 17:36:11

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索