Skip to content

Commit 25ac447

Browse files
author
Haibo Chen
committed
MAPREDUCE-6673. Add a test example job that grows in memory usage over time (Karthik Kambatla via Haibo Chen)
Change-Id: Iccfc8c67c38c526cc61726d87bfcbcf69ac36fea
1 parent 0ac17dc commit 25ac447

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.hadoop.mapreduce;
19+
20+
import org.apache.commons.logging.Log;
21+
import org.apache.commons.logging.LogFactory;
22+
import org.apache.hadoop.conf.Configuration;
23+
import org.apache.hadoop.io.IntWritable;
24+
import org.apache.hadoop.util.ToolRunner;
25+
26+
import java.io.IOException;
27+
import java.util.ArrayList;
28+
29+
/**
30+
* A sleep job whose mappers create 1MB buffer for every record.
31+
*/
32+
public class GrowingSleepJob extends SleepJob {
33+
private static final Log LOG = LogFactory.getLog(GrowingSleepJob.class);
34+
35+
public static class GrowingSleepMapper extends SleepMapper {
36+
private final int MB = 1024 * 1024;
37+
private ArrayList<byte[]> bytes = new ArrayList<>();
38+
39+
@Override
40+
public void map(IntWritable key, IntWritable value, Context context)
41+
throws IOException, InterruptedException {
42+
super.map(key, value, context);
43+
long free = Runtime.getRuntime().freeMemory();
44+
if (free > 32 * MB) {
45+
LOG.info("Free memory = " + free +
46+
" bytes. Creating 1 MB on the heap.");
47+
bytes.add(new byte[MB]);
48+
}
49+
}
50+
}
51+
52+
public static void main(String[] args) throws Exception {
53+
int res = ToolRunner.run(new Configuration(), new GrowingSleepJob(), args);
54+
System.exit(res);
55+
}
56+
57+
@Override
58+
public Job createJob(int numMapper, int numReducer,
59+
long mapSleepTime, int mapSleepCount,
60+
long reduceSleepTime, int reduceSleepCount)
61+
throws IOException {
62+
Job job = super.createJob(numMapper, numReducer, mapSleepTime,
63+
mapSleepCount, reduceSleepTime, reduceSleepCount);
64+
job.setMapperClass(GrowingSleepMapper.class);
65+
job.setJobName("Growing sleep job");
66+
return job;
67+
}
68+
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import org.apache.hadoop.mapred.TestTextInputFormat;
4343
import org.apache.hadoop.mapred.ThreadedMapBenchmark;
4444
import org.apache.hadoop.mapreduce.FailJob;
45+
import org.apache.hadoop.mapreduce.GrowingSleepJob;
4546
import org.apache.hadoop.mapreduce.LargeSorter;
4647
import org.apache.hadoop.mapreduce.MiniHadoopClusterManager;
4748
import org.apache.hadoop.mapreduce.SleepJob;
@@ -90,6 +91,8 @@ public MapredTestDriver(ProgramDriver pgd) {
9091
pgd.addClass("fail", FailJob.class, "a job that always fails");
9192
pgd.addClass("sleep", SleepJob.class,
9293
"A job that sleeps at each map and reduce task.");
94+
pgd.addClass("gsleep", GrowingSleepJob.class,
95+
"A sleep job whose mappers create 1MB buffer for every record.");
9396
pgd.addClass("timelineperformance", TimelineServicePerformance.class,
9497
"A job that launches mappers to test timline service " +
9598
"performance.");

0 commit comments

Comments
 (0)