MAPREDUCE-4083. [Gridmix] NPE in cpu emulation. (amarrk)

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1325145 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Amar Kamat 2012-04-12 07:17:34 +00:00
parent 4ea042666c
commit d310c48ce4
5 changed files with 23 additions and 6 deletions

View File

@ -52,6 +52,8 @@ Trunk (unreleased changes)
BUG FIXES
MAPREDUCE-4083. [Gridmix] NPE in cpu emulation. (amarrk)
MAPREDUCE-4087. [Gridmix] GenerateDistCacheData job of Gridmix can
become slow in some cases (ravigummadi).

View File

@ -235,7 +235,9 @@ implements ResourceUsageEmulatorPlugin {
@Override
public float getProgress() {
return Math.min(1f, ((float)getCurrentCPUUsage())/targetCpuUsage);
return enabled
? Math.min(1f, ((float)getCurrentCPUUsage())/targetCpuUsage)
: 1.0f;
}
@Override
@ -297,6 +299,9 @@ implements ResourceUsageEmulatorPlugin {
public void initialize(Configuration conf, ResourceUsageMetrics metrics,
ResourceCalculatorPlugin monitor,
Progressive progress) {
this.monitor = monitor;
this.progress = progress;
// get the target CPU usage
targetCpuUsage = metrics.getCumulativeCpuUsage();
if (targetCpuUsage <= 0 ) {
@ -306,8 +311,6 @@ implements ResourceUsageEmulatorPlugin {
enabled = true;
}
this.monitor = monitor;
this.progress = progress;
emulationInterval = conf.getFloat(CPU_EMULATION_PROGRESS_INTERVAL,
DEFAULT_EMULATION_FREQUENCY);

View File

@ -188,7 +188,9 @@ implements ResourceUsageEmulatorPlugin {
@Override
public float getProgress() {
return Math.min(1f, ((float)getTotalHeapUsageInMB())/targetHeapUsageInMB);
return enabled
? Math.min(1f, ((float)getTotalHeapUsageInMB())/targetHeapUsageInMB)
: 1.0f;
}
@Override
@ -237,6 +239,8 @@ implements ResourceUsageEmulatorPlugin {
public void initialize(Configuration conf, ResourceUsageMetrics metrics,
ResourceCalculatorPlugin monitor,
Progressive progress) {
this.progress = progress;
// get the target heap usage
targetHeapUsageInMB = metrics.getHeapUsage() / ONE_MB;
if (targetHeapUsageInMB <= 0 ) {
@ -248,7 +252,6 @@ implements ResourceUsageEmulatorPlugin {
enabled = true;
}
this.progress = progress;
emulationInterval =
conf.getFloat(HEAP_EMULATION_PROGRESS_INTERVAL,
DEFAULT_EMULATION_PROGRESS_INTERVAL);

View File

@ -171,6 +171,11 @@ public class TestGridmixMemoryEmulation {
assertEquals("Disabled heap usage emulation plugin works!",
heapUsagePre, heapUsagePost);
// test with get progress
float progress = heapPlugin.getProgress();
assertEquals("Invalid progress of disabled cumulative heap usage emulation "
+ "plugin!", 1.0f, progress, 0f);
// test with wrong/invalid configuration
Boolean failed = null;
invalidUsage =

View File

@ -32,7 +32,6 @@ import org.apache.hadoop.mapreduce.TaskType;
import org.apache.hadoop.mapreduce.server.tasktracker.TTConfig;
import org.apache.hadoop.mapreduce.task.MapContextImpl;
import org.apache.hadoop.mapreduce.util.ResourceCalculatorPlugin;
import org.apache.hadoop.yarn.util.ResourceCalculatorPlugin.ProcResourceValues;
import org.apache.hadoop.tools.rumen.ResourceUsageMetrics;
import org.apache.hadoop.mapred.DummyResourceCalculatorPlugin;
import org.apache.hadoop.mapred.gridmix.LoadJob.ResourceUsageMatcherRunner;
@ -484,6 +483,11 @@ public class TestResourceUsageEmulators {
assertEquals("Disabled cumulative CPU usage emulation plugin works!",
cpuUsagePre, cpuUsagePost);
// test with get progress
float progress = cpuPlugin.getProgress();
assertEquals("Invalid progress of disabled cumulative CPU usage emulation "
+ "plugin!", 1.0f, progress, 0f);
// test with valid resource usage value
ResourceUsageMetrics metrics = createMetrics(targetCpuUsage);