From e06c23a6c92ef783cdb45447fa2abd1ab48d166f Mon Sep 17 00:00:00 2001 From: Zhijie Shen Date: Tue, 4 Nov 2014 15:50:10 -0800 Subject: [PATCH] YARN-2752. Made ContainerExecutor append "nice -n" arg only when priority adjustment flag is set. Contributed by Xuan Gong. --- hadoop-yarn-project/CHANGES.txt | 3 ++ .../server/nodemanager/ContainerExecutor.java | 31 ++++++++++++------- .../nodemanager/TestContainerExecutor.java | 2 +- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/hadoop-yarn-project/CHANGES.txt b/hadoop-yarn-project/CHANGES.txt index a50da38e153..fc580864a21 100644 --- a/hadoop-yarn-project/CHANGES.txt +++ b/hadoop-yarn-project/CHANGES.txt @@ -826,6 +826,9 @@ Release 2.6.0 - UNRELEASED of races between the launch and the stop-container call and when root processes crash. (Billie Rinaldi via vinodkv) + YARN-2752. Made ContainerExecutor append "nice -n" arg only when priority + adjustment flag is set. (Xuan Gong via zjshen) + Release 2.5.1 - 2014-09-05 INCOMPATIBLE CHANGES diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/ContainerExecutor.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/ContainerExecutor.java index 3b866d3b1b9..4ce1a750764 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/ContainerExecutor.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/ContainerExecutor.java @@ -276,32 +276,39 @@ public abstract class ContainerExecutor implements Configurable { } /** - * Return a command to execute the given command in OS shell. - * On Windows, the passed in groupId can be used to launch - * and associate the given groupId in a process group. On - * non-Windows, groupId is ignored. + * Return a command to execute the given command in OS shell. + * On Windows, the passed in groupId can be used to launch + * and associate the given groupId in a process group. On + * non-Windows, groupId is ignored. */ protected String[] getRunCommand(String command, String groupId, - String userName, Path pidFile, Configuration conf) { + String userName, Path pidFile, Configuration conf) { + boolean containerSchedPriorityIsSet = false; int containerSchedPriorityAdjustment = YarnConfiguration.DEFAULT_NM_CONTAINER_EXECUTOR_SCHED_PRIORITY; - if (conf.get(YarnConfiguration.NM_CONTAINER_EXECUTOR_SCHED_PRIORITY) != + + if (conf.get(YarnConfiguration.NM_CONTAINER_EXECUTOR_SCHED_PRIORITY) != null) { - containerSchedPriorityAdjustment = conf - .getInt(YarnConfiguration.NM_CONTAINER_EXECUTOR_SCHED_PRIORITY, 0); + containerSchedPriorityIsSet = true; + containerSchedPriorityAdjustment = conf + .getInt(YarnConfiguration.NM_CONTAINER_EXECUTOR_SCHED_PRIORITY, + YarnConfiguration.DEFAULT_NM_CONTAINER_EXECUTOR_SCHED_PRIORITY); } - + if (Shell.WINDOWS) { return new String[] { Shell.WINUTILS, "task", "create", groupId, "cmd /c " + command }; } else { List retCommand = new ArrayList(); - retCommand.addAll(Arrays.asList("nice", "-n", - Integer.toString(containerSchedPriorityAdjustment))); + if (containerSchedPriorityIsSet) { + retCommand.addAll(Arrays.asList("nice", "-n", + Integer.toString(containerSchedPriorityAdjustment))); + } retCommand.addAll(Arrays.asList("bash", command)); return retCommand.toArray(new String[retCommand.size()]); } - } + + } /** * Is the container still active? diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestContainerExecutor.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestContainerExecutor.java index 96be782c307..fd3634bd1c9 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestContainerExecutor.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestContainerExecutor.java @@ -34,7 +34,7 @@ public class TestContainerExecutor { public void testRunCommandNoPriority() throws Exception { Configuration conf = new Configuration(); String[] command = containerExecutor.getRunCommand("echo", "group1", "user", null, conf); - assertTrue("first command should be the run command for the platform " + command[0], + assertTrue("first command should be the run command for the platform", command[0].equals(Shell.WINUTILS) || command[0].equals("bash")); }