From db3cf5b3544e176227ce30caaefeb9f81bbd198e Mon Sep 17 00:00:00 2001 From: Jian He Date: Thu, 19 May 2016 19:25:16 -0700 Subject: [PATCH] MAPREDUCE-6696. Add a configuration to limit the number of map tasks allowed per job. Contributed by Zhihai Xu (cherry picked from commit 21d2b90213e8e188bcac31f9360c5176ac89d083) --- .../apache/hadoop/mapreduce/JobSubmitter.java | 7 ++++++ .../apache/hadoop/mapreduce/MRJobConfig.java | 7 ++++++ .../src/main/resources/mapred-default.xml | 8 +++++++ .../hadoop/mapred/TestLocalJobSubmission.java | 24 ++++++++++++++++++- 4 files changed, 45 insertions(+), 1 deletion(-) diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/JobSubmitter.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/JobSubmitter.java index 18b76a1653a..497b0ed3193 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/JobSubmitter.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/JobSubmitter.java @@ -200,6 +200,13 @@ class JobSubmitter { conf.setInt(MRJobConfig.NUM_MAPS, maps); LOG.info("number of splits:" + maps); + int maxMaps = conf.getInt(MRJobConfig.JOB_MAX_MAP, + MRJobConfig.DEFAULT_JOB_MAX_MAP); + if (maxMaps >= 0 && maxMaps < maps) { + throw new IllegalArgumentException("The number of map tasks " + maps + + " exceeded limit " + maxMaps); + } + // write "queue admins of the queue to which job is being submitted" // to job file. String queue = conf.get(MRJobConfig.QUEUE_NAME, diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/MRJobConfig.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/MRJobConfig.java index 45033fff4ab..6d60bbf4b12 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/MRJobConfig.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/MRJobConfig.java @@ -422,6 +422,13 @@ public interface MRJobConfig { "mapreduce.job.running.reduce.limit"; public static final int DEFAULT_JOB_RUNNING_REDUCE_LIMIT = 0; + /* Config for Limit on the number of map tasks allowed per job + * There is no limit if this value is negative. + */ + public static final String JOB_MAX_MAP = + "mapreduce.job.max.map"; + public static final int DEFAULT_JOB_MAX_MAP = -1; + /* config for tracking the local file where all the credentials for the job * credentials. */ diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/resources/mapred-default.xml b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/resources/mapred-default.xml index d571448dbfa..5221e436959 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/resources/mapred-default.xml +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/resources/mapred-default.xml @@ -98,6 +98,14 @@ + + mapreduce.job.max.map + -1 + Limit on the number of map tasks allowed per job. + There is no limit if this value is negative. + + + mapreduce.job.reducer.preempt.delay.sec 0 diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapred/TestLocalJobSubmission.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapred/TestLocalJobSubmission.java index 8b02857b23a..f7352f1a08d 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapred/TestLocalJobSubmission.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapred/TestLocalJobSubmission.java @@ -57,7 +57,7 @@ public class TestLocalJobSubmission { /** * test the local job submission options of - * -jt local -libjars + * -jt local -libjars. * @throws IOException */ @Test @@ -106,6 +106,28 @@ public class TestLocalJobSubmission { assertEquals("dist job res is not 0:", 0, res); } + /** + * test JOB_MAX_MAP configuration. + * @throws Exception + */ + @Test + public void testJobMaxMapConfig() throws Exception { + Configuration conf = new Configuration(); + conf.set(MRConfig.FRAMEWORK_NAME, "local"); + conf.setInt(MRJobConfig.JOB_MAX_MAP, 0); + final String[] args = { + "-m", "1", "-r", "1", "-mt", "1", "-rt", "1" + }; + int res = -1; + try { + res = ToolRunner.run(conf, new SleepJob(), args); + fail("Job should fail"); + } catch (IllegalArgumentException e) { + assertTrue(e.getLocalizedMessage().contains( + "The number of map tasks 1 exceeded limit")); + } + } + private Path makeJar(Path p) throws IOException { FileOutputStream fos = new FileOutputStream(new File(p.toString())); JarOutputStream jos = new JarOutputStream(fos);