From 8f43934e9940270e0adfec8c00b7635060e8a4d0 Mon Sep 17 00:00:00 2001 From: Thomas Graves Date: Tue, 26 Mar 2013 19:08:26 +0000 Subject: [PATCH] MAPREDUCE-4083. [Gridmix] NPE in cpu emulation. (amarrk via tgraves) git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1461272 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-mapreduce-project/CHANGES.txt | 2 ++ .../resourceusage/CumulativeCpuUsageEmulatorPlugin.java | 9 ++++++--- .../resourceusage/TotalHeapUsageEmulatorPlugin.java | 7 +++++-- .../mapred/gridmix/TestGridmixMemoryEmulation.java | 5 +++++ .../mapred/gridmix/TestResourceUsageEmulators.java | 5 +++++ 5 files changed, 23 insertions(+), 5 deletions(-) diff --git a/hadoop-mapreduce-project/CHANGES.txt b/hadoop-mapreduce-project/CHANGES.txt index f05ccc6f05c..b1ac3c88037 100644 --- a/hadoop-mapreduce-project/CHANGES.txt +++ b/hadoop-mapreduce-project/CHANGES.txt @@ -96,6 +96,8 @@ Release 2.0.5-beta - UNRELEASED MAPREDUCE-3008. Improvements to cumulative CPU emulation for short running tasks in Gridmix. (amarrk via tgraves) + MAPREDUCE-4083. [Gridmix] NPE in cpu emulation. (amarrk via tgraves) + Release 2.0.4-alpha - UNRELEASED INCOMPATIBLE CHANGES diff --git a/hadoop-tools/hadoop-gridmix/src/main/java/org/apache/hadoop/mapred/gridmix/emulators/resourceusage/CumulativeCpuUsageEmulatorPlugin.java b/hadoop-tools/hadoop-gridmix/src/main/java/org/apache/hadoop/mapred/gridmix/emulators/resourceusage/CumulativeCpuUsageEmulatorPlugin.java index 7ed118e0c88..52944b65de1 100644 --- a/hadoop-tools/hadoop-gridmix/src/main/java/org/apache/hadoop/mapred/gridmix/emulators/resourceusage/CumulativeCpuUsageEmulatorPlugin.java +++ b/hadoop-tools/hadoop-gridmix/src/main/java/org/apache/hadoop/mapred/gridmix/emulators/resourceusage/CumulativeCpuUsageEmulatorPlugin.java @@ -236,7 +236,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 @@ -298,6 +300,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 ) { @@ -307,8 +312,6 @@ implements ResourceUsageEmulatorPlugin { enabled = true; } - this.monitor = monitor; - this.progress = progress; emulationInterval = conf.getFloat(CPU_EMULATION_PROGRESS_INTERVAL, DEFAULT_EMULATION_FREQUENCY); diff --git a/hadoop-tools/hadoop-gridmix/src/main/java/org/apache/hadoop/mapred/gridmix/emulators/resourceusage/TotalHeapUsageEmulatorPlugin.java b/hadoop-tools/hadoop-gridmix/src/main/java/org/apache/hadoop/mapred/gridmix/emulators/resourceusage/TotalHeapUsageEmulatorPlugin.java index 0ac8e7dc918..b9971dc2af5 100644 --- a/hadoop-tools/hadoop-gridmix/src/main/java/org/apache/hadoop/mapred/gridmix/emulators/resourceusage/TotalHeapUsageEmulatorPlugin.java +++ b/hadoop-tools/hadoop-gridmix/src/main/java/org/apache/hadoop/mapred/gridmix/emulators/resourceusage/TotalHeapUsageEmulatorPlugin.java @@ -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); diff --git a/hadoop-tools/hadoop-gridmix/src/test/java/org/apache/hadoop/mapred/gridmix/TestGridmixMemoryEmulation.java b/hadoop-tools/hadoop-gridmix/src/test/java/org/apache/hadoop/mapred/gridmix/TestGridmixMemoryEmulation.java index 2929d6a794f..7ec3c93d367 100644 --- a/hadoop-tools/hadoop-gridmix/src/test/java/org/apache/hadoop/mapred/gridmix/TestGridmixMemoryEmulation.java +++ b/hadoop-tools/hadoop-gridmix/src/test/java/org/apache/hadoop/mapred/gridmix/TestGridmixMemoryEmulation.java @@ -170,6 +170,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 = diff --git a/hadoop-tools/hadoop-gridmix/src/test/java/org/apache/hadoop/mapred/gridmix/TestResourceUsageEmulators.java b/hadoop-tools/hadoop-gridmix/src/test/java/org/apache/hadoop/mapred/gridmix/TestResourceUsageEmulators.java index feafafaaa37..f14087bf3af 100644 --- a/hadoop-tools/hadoop-gridmix/src/test/java/org/apache/hadoop/mapred/gridmix/TestResourceUsageEmulators.java +++ b/hadoop-tools/hadoop-gridmix/src/test/java/org/apache/hadoop/mapred/gridmix/TestResourceUsageEmulators.java @@ -472,6 +472,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);