ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From swa...@apache.org
Subject ambari git commit: UI lags and OutOfMemoryError seen in Ambari server after dashboard metrics' time periods are changed. (Aravindan Vijayan via swagle)
Date Fri, 13 Nov 2015 06:44:26 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-2.1 cc77797be -> 5587263a9


UI lags and OutOfMemoryError seen in Ambari server after dashboard metrics' time periods are
changed. (Aravindan Vijayan via swagle)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/5587263a
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/5587263a
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/5587263a

Branch: refs/heads/branch-2.1
Commit: 5587263a9c649ad90906afeed358a4ec7563f00d
Parents: cc77797
Author: Siddharth Wagle <swagle@hortonworks.com>
Authored: Thu Nov 12 22:44:20 2015 -0800
Committer: Siddharth Wagle <swagle@hortonworks.com>
Committed: Thu Nov 12 22:44:20 2015 -0800

----------------------------------------------------------------------
 .../metrics/MetricsPaddingMethod.java           | 47 ++++++++++-----
 .../timeline/MetricsPaddingMethodTest.java      | 63 +++++++++++++++++++-
 2 files changed, 93 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/5587263a/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/MetricsPaddingMethod.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/MetricsPaddingMethod.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/MetricsPaddingMethod.java
index ccfb713..930cb91 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/MetricsPaddingMethod.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/MetricsPaddingMethod.java
@@ -18,10 +18,11 @@
 package org.apache.ambari.server.controller.metrics;
 
 import org.apache.ambari.server.controller.spi.TemporalInfo;
+import org.apache.hadoop.metrics2.sink.timeline.Precision;
 import org.apache.hadoop.metrics2.sink.timeline.TimelineMetric;
 import java.util.Iterator;
-import java.util.Map;
 import java.util.TreeMap;
+import java.util.concurrent.TimeUnit;
 
 public class MetricsPaddingMethod {
   private final PADDING_STRATEGY strategy;
@@ -54,7 +55,12 @@ public class MetricsPaddingMethod {
 
     TreeMap<Long, Double> values = metric.getMetricValues();
 
-    long dataInterval = getTimelineMetricInterval(values);
+    long intervalStartTime = longToMillis(temporalInfo.getStartTime());
+    long intervalEndTime = longToMillis(temporalInfo.getEndTime());
+    long dataStartTime = longToMillis(values.firstKey());
+    long dataEndTime = longToMillis(values.lastKey());
+
+    long dataInterval = getTimelineMetricInterval(values, intervalStartTime, intervalEndTime);
 
     if (dataInterval == -1 || dataInterval < MINIMUM_STEP_INTERVAL) {
       dataInterval = temporalInfo.getStep() != null ? temporalInfo.getStep() : -1;
@@ -64,11 +70,6 @@ public class MetricsPaddingMethod {
       return;
     }
 
-    long intervalStartTime = longToMillis(temporalInfo.getStartTime());
-    long intervalEndTime = longToMillis(temporalInfo.getEndTime());
-    long dataStartTime = longToMillis(values.firstKey());
-    long dataEndTime = longToMillis(values.lastKey());
-
     Double paddingValue = 0.0d;
 
     if (strategy.equals(PADDING_STRATEGY.NULLS)) {
@@ -94,14 +95,30 @@ public class MetricsPaddingMethod {
     return time;
   }
 
-  private long getTimelineMetricInterval(TreeMap<Long, Double> values) {
-    if (values != null && values.size() > 1) {
-      Iterator<Long> tsValuesIterator = values.descendingKeySet().iterator();
-      long lastValue = tsValuesIterator.next();
-      long secondToLastValue = tsValuesIterator.next();
-      return Math.abs(lastValue - secondToLastValue);
+  private long getTimelineMetricInterval(TreeMap<Long, Double> values, long startTime,
long endTime) {
+
+    Precision precision = Precision.getPrecision(startTime, endTime);
+    long interval;
+
+    if (precision.equals(Precision.DAYS)) {
+      interval = TimeUnit.DAYS.toMillis(1);
+    } else if (precision.equals(Precision.HOURS)) {
+      interval = TimeUnit.HOURS.toMillis(1);
+    } else if (precision.equals(Precision.MINUTES)) {
+      interval = TimeUnit.MINUTES.toMillis(1);
+    } else {
+      //Precision = SECONDS.
+      //More than 1 point.
+      if (values != null && values.size() > 1) {
+        Iterator<Long> tsValuesIterator = values.descendingKeySet().iterator();
+        long lastValue = tsValuesIterator.next();
+        long secondToLastValue = tsValuesIterator.next();
+        interval =  Math.abs(lastValue - secondToLastValue);
+      } else {
+        // Only 1 point
+        interval = -1;
+      }
     }
-    // No values found or only one value found
-    return -1;
+    return interval;
   }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/5587263a/ambari-server/src/test/java/org/apache/ambari/server/controller/metrics/timeline/MetricsPaddingMethodTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/metrics/timeline/MetricsPaddingMethodTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/controller/metrics/timeline/MetricsPaddingMethodTest.java
index b35295d..58c8aa0 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/metrics/timeline/MetricsPaddingMethodTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/metrics/timeline/MetricsPaddingMethodTest.java
@@ -22,7 +22,6 @@ import org.apache.ambari.server.controller.metrics.MetricsPaddingMethod;
 import org.apache.ambari.server.controller.spi.TemporalInfo;
 import org.apache.hadoop.metrics2.sink.timeline.TimelineMetric;
 import org.junit.Test;
-import java.util.Map;
 import java.util.TreeMap;
 
 public class MetricsPaddingMethodTest {
@@ -138,7 +137,7 @@ public class MetricsPaddingMethodTest {
   }
 
   @Test
-  public void testPaddingWithOneValueReturnedNoStepProvided() throws Exception {
+  public void testPaddingWithOneValue() throws Exception {
     MetricsPaddingMethod paddingMethod =
       new MetricsPaddingMethod(MetricsPaddingMethod.PADDING_STRATEGY.ZEROS);
 
@@ -163,6 +162,66 @@ public class MetricsPaddingMethodTest {
   }
 
   @Test
+  public void testPaddingWithWithVariousPrecisionData() throws Exception {
+    MetricsPaddingMethod paddingMethod =
+      new MetricsPaddingMethod(MetricsPaddingMethod.PADDING_STRATEGY.ZEROS);
+
+    long now = System.currentTimeMillis();
+    TimelineMetric timelineMetric = new TimelineMetric();
+    timelineMetric.setMetricName("m1");
+    timelineMetric.setHostName("h1");
+    timelineMetric.setAppId("a1");
+    timelineMetric.setTimestamp(now);
+    TreeMap<Long, Double> inputValues = new TreeMap<Long, Double>();
+
+    long seconds = 1000;
+    long minute = 60*seconds;
+    long hour = 60*minute;
+    long day = 24*hour;
+
+    //MINUTES
+    inputValues.clear();
+    for(int i=5;i>=1;i--) {
+      inputValues.put(now - i*minute, i+ 0.0);
+    }
+    timelineMetric.setMetricValues(inputValues);
+
+    TemporalInfo temporalInfo = getTemporalInfo(now - 2*hour - 1*minute, now, null);
+    paddingMethod.applyPaddingStrategy(timelineMetric, temporalInfo);
+    TreeMap<Long, Double> values = (TreeMap<Long, Double>) timelineMetric.getMetricValues();
+
+    Assert.assertEquals(122, values.size());
+    Assert.assertEquals(new Long(now - 2*hour - 1*minute), values.keySet().iterator().next());
+
+    //HOURS
+    inputValues.clear();
+    for(int i=5;i>=1;i--) {
+      inputValues.put(now - i*hour, i+ 0.0);
+    }
+    timelineMetric.setMetricValues(inputValues);
+
+    temporalInfo = getTemporalInfo(now - 1*day - 1*hour, now, null);
+    paddingMethod.applyPaddingStrategy(timelineMetric, temporalInfo);
+    values = (TreeMap<Long, Double>) timelineMetric.getMetricValues();
+
+    Assert.assertEquals(26, values.size());
+    Assert.assertEquals(new Long(now - 1*day - 1*hour), values.keySet().iterator().next());
+
+    //DAYS
+    inputValues.clear();
+    inputValues.put(now - day, 1.0);
+    timelineMetric.setMetricValues(inputValues);
+
+    temporalInfo = getTemporalInfo(now - 40*day, now, null);
+    paddingMethod.applyPaddingStrategy(timelineMetric, temporalInfo);
+    values = (TreeMap<Long, Double>) timelineMetric.getMetricValues();
+
+    Assert.assertEquals(41, values.size());
+    Assert.assertEquals(new Long(now - 40*day), values.keySet().iterator().next());
+  }
+
+
+  @Test
   public void testNoPaddingRequested() throws Exception {
     MetricsPaddingMethod paddingMethod =
       new MetricsPaddingMethod(MetricsPaddingMethod.PADDING_STRATEGY.NONE);


Mime
View raw message