前向hadoop提交的任务数越来越多, 任务的执行是按照FIFO的默认调度算法执行的,这样会造成一些任务,即使只有1,2个map或reduce,独占资源的现象,因此改为公平调度算法。
cdh hadoop 0.20.2+320 的hadoop lib目录已经包含公平调度算法的包。如果没有应该从$HADOOP_HOME/contrib/fairscheduler目录下,把那个jar包(我在这里是hadoop-fairscheduler-0.20.2+320.jar)复制到lib目录下。然后修改配置文件:
1。在mapred-site.xml 中将
<property>
<name>mapred.jobtracker.taskScheduler</name>
<value>org.apache.hadoop.mapred.JobQueueTaskScheduler</value>
<description>The class responsible for scheduling the tasks.</description>
</property>
改为
<property>
<name>mapred.jobtracker.taskScheduler</name>
<value>org.apache.hadoop.mapred.FairScheduler</value>
<description>The class responsible for scheduling the tasks.</description>
</property>
2。在mapred-site.xml 中加入:
<property>
<name>mapred.fairscheduler.allocation.file</name>
<value>/usr/local/hadoop/conf/pools.xml</value>
</property>
3。创建/usr/local/hadoop/conf/pools.xml
文件内容:
<?xml version="1.0"?>
<allocations>
<pool name="root">
<minMaps>10</minMaps>
<minReduces>5</minReduces>
</pool>
<user name="root">
<maxRunningJobs>6</maxRunningJobs>
</user>
<userMaxJobsDefault>3</userMaxJobsDefault>
</allocations>
其中
<user name="root">
<maxRunningJobs>6</maxRunningJobs>
</user>
规定用户root可同时运行的job数量;
<pool name="root">
<minMaps>10</minMaps>
<minReduces>5</minReduces>
</pool>
规定这个池的最小map和reduce数量;
<userMaxJobsDefault>3</userMaxJobsDefault>
规定未指定用户可提交的最大job数量;