Skip to content

Commit f19771a

Browse files
committed
MAPREDUCE-5970. Provide a boolean switch to enable MR-AM profiling. Contributed by Gera Shegalov
1 parent 1862064 commit f19771a

File tree

5 files changed

+58
-6
lines changed

5 files changed

+58
-6
lines changed

hadoop-mapreduce-project/CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,9 @@ Release 2.6.0 - UNRELEASED
274274

275275
MAPREDUCE-6072. Remove INSTALL document (Akira AJISAKA via aw)
276276

277+
MAPREDUCE-5970. Provide a boolean switch to enable MR-AM profiling (Gera
278+
Shegalov via jlowe)
279+
277280
OPTIMIZATIONS
278281

279282
BUG FIXES

hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapred/JobConf.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1643,8 +1643,7 @@ public void setProfileEnabled(boolean newValue) {
16431643
*/
16441644
public String getProfileParams() {
16451645
return get(JobContext.TASK_PROFILE_PARAMS,
1646-
"-agentlib:hprof=cpu=samples,heap=sites,force=n,thread=y," +
1647-
"verbose=n,file=%s");
1646+
MRJobConfig.DEFAULT_TASK_PROFILE_PARAMS);
16481647
}
16491648

16501649
/**

hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/MRJobConfig.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,10 @@ public interface MRJobConfig {
184184

185185
public static final String TASK_PROFILE_PARAMS = "mapreduce.task.profile.params";
186186

187+
public static final String DEFAULT_TASK_PROFILE_PARAMS =
188+
"-agentlib:hprof=cpu=samples,heap=sites,force=n,thread=y,"
189+
+ "verbose=n,file=%s";
190+
187191
public static final String NUM_MAP_PROFILES = "mapreduce.task.profile.maps";
188192

189193
public static final String NUM_REDUCE_PROFILES = "mapreduce.task.profile.reduces";
@@ -614,7 +618,12 @@ public interface MRJobConfig {
614618

615619
public static final String MR_AM_ADMIN_USER_ENV =
616620
MR_AM_PREFIX + "admin.user.env";
617-
621+
622+
public static final String MR_AM_PROFILE = MR_AM_PREFIX + "profile";
623+
public static final boolean DEFAULT_MR_AM_PROFILE = false;
624+
public static final String MR_AM_PROFILE_PARAMS = MR_AM_PREFIX
625+
+ "profile.params";
626+
618627
public static final String MAPRED_MAP_ADMIN_JAVA_OPTS =
619628
"mapreduce.admin.map.child.java.opts";
620629

hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/main/java/org/apache/hadoop/mapred/YARNRunner.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ public ApplicationSubmissionContext createApplicationSubmissionContext(
408408
warnForJavaLibPath(conf.get(MRJobConfig.REDUCE_JAVA_OPTS,""), "reduce",
409409
MRJobConfig.REDUCE_JAVA_OPTS, MRJobConfig.REDUCE_ENV);
410410
warnForJavaLibPath(conf.get(MRJobConfig.MAPRED_REDUCE_ADMIN_JAVA_OPTS,""), "reduce",
411-
MRJobConfig.MAPRED_REDUCE_ADMIN_JAVA_OPTS, MRJobConfig.MAPRED_ADMIN_USER_ENV);
411+
MRJobConfig.MAPRED_REDUCE_ADMIN_JAVA_OPTS, MRJobConfig.MAPRED_ADMIN_USER_ENV);
412412

413413
// Add AM admin command opts before user command opts
414414
// so that it can be overridden by user
@@ -424,7 +424,18 @@ public ApplicationSubmissionContext createApplicationSubmissionContext(
424424
warnForJavaLibPath(mrAppMasterUserOptions, "app master",
425425
MRJobConfig.MR_AM_COMMAND_OPTS, MRJobConfig.MR_AM_ENV);
426426
vargs.add(mrAppMasterUserOptions);
427-
427+
428+
if (jobConf.getBoolean(MRJobConfig.MR_AM_PROFILE,
429+
MRJobConfig.DEFAULT_MR_AM_PROFILE)) {
430+
final String profileParams = jobConf.get(MRJobConfig.MR_AM_PROFILE_PARAMS,
431+
MRJobConfig.DEFAULT_TASK_PROFILE_PARAMS);
432+
if (profileParams != null) {
433+
vargs.add(String.format(profileParams,
434+
ApplicationConstants.LOG_DIR_EXPANSION_VAR + Path.SEPARATOR
435+
+ TaskLog.LogName.PROFILE));
436+
}
437+
}
438+
428439
vargs.add(MRJobConfig.APPLICATION_MASTER_CLASS);
429440
vargs.add("1>" + ApplicationConstants.LOG_DIR_EXPANSION_VAR +
430441
Path.SEPARATOR + ApplicationConstants.STDOUT);

hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapred/TestYARNRunner.java

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929

3030
import java.io.ByteArrayOutputStream;
3131
import java.io.File;
32-
import java.io.FileNotFoundException;
3332
import java.io.FileOutputStream;
3433
import java.io.IOException;
3534
import java.io.OutputStream;
@@ -115,6 +114,11 @@ public class TestYARNRunner extends TestCase {
115114
private static final Log LOG = LogFactory.getLog(TestYARNRunner.class);
116115
private static final RecordFactory recordFactory = RecordFactoryProvider.getRecordFactory(null);
117116

117+
// prefix before <LOG_DIR>/profile.out
118+
private static final String PROFILE_PARAMS =
119+
MRJobConfig.DEFAULT_TASK_PROFILE_PARAMS.substring(0,
120+
MRJobConfig.DEFAULT_TASK_PROFILE_PARAMS.lastIndexOf("%"));
121+
118122
private YARNRunner yarnRunner;
119123
private ResourceMgrDelegate resourceMgrDelegate;
120124
private YarnConfiguration conf;
@@ -423,6 +427,8 @@ public void testAMAdminCommandOpts() throws Exception {
423427

424428
for(String command : commands) {
425429
if(command != null) {
430+
assertFalse("Profiler should be disabled by default",
431+
command.contains(PROFILE_PARAMS));
426432
adminPos = command.indexOf("-Djava.net.preferIPv4Stack=true");
427433
if(adminPos >= 0)
428434
adminIndex = index;
@@ -479,6 +485,30 @@ public void testWarnCommandOpts() throws Exception {
479485
"using yarn.app.mapreduce.am.env config settings."));
480486
}
481487

488+
@Test(timeout=20000)
489+
public void testAMProfiler() throws Exception {
490+
JobConf jobConf = new JobConf();
491+
492+
jobConf.setBoolean(MRJobConfig.MR_AM_PROFILE, true);
493+
494+
YARNRunner yarnRunner = new YARNRunner(jobConf);
495+
496+
ApplicationSubmissionContext submissionContext =
497+
buildSubmitContext(yarnRunner, jobConf);
498+
499+
ContainerLaunchContext containerSpec = submissionContext.getAMContainerSpec();
500+
List<String> commands = containerSpec.getCommands();
501+
502+
for(String command : commands) {
503+
if (command != null) {
504+
if (command.contains(PROFILE_PARAMS)) {
505+
return;
506+
}
507+
}
508+
}
509+
throw new IllegalStateException("Profiler opts not found!");
510+
}
511+
482512
@Test
483513
public void testAMStandardEnv() throws Exception {
484514
final String ADMIN_LIB_PATH = "foo";

0 commit comments

Comments
 (0)