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

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

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

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

    这里配置了三个队列,分别是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:

    conf.setQueueName("hive");

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

    set mapred.job.queue.name=pig;

    动态更新集群队列和容量

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

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

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

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

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

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

  • 相关阅读:
    448-查找数组中消失的所有数字
    977 -排序数组的正方形
    爬虫小总结
    增量式爬虫
    分布式爬虫
    CrawlSpider:类,Spider的一个子类
    中间件
    中间件
    scrapy图片数据爬取之ImagesPipeline
    scrapy五大核心组件
  • 原文地址:https://www.cnblogs.com/ggjucheng/p/2608817.html
Copyright © 2020-2023  润新知