You are viewing a plain text version of this content. The canonical link for it is here.
Posted to gitbox@hive.apache.org by GitBox <gi...@apache.org> on 2021/05/26 08:20:29 UTC

[GitHub] [hive] ayushtkn opened a new pull request #2321: HIVE-25165. Generate & track statistics per event type for incremental load in replication metrics.

ayushtkn opened a new pull request #2321:
URL: https://github.com/apache/hive/pull/2321


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] ayushtkn commented on a change in pull request #2321: HIVE-25165. Generate & track statistics per event type for incremental load in replication metrics.

Posted by GitBox <gi...@apache.org>.
ayushtkn commented on a change in pull request #2321:
URL: https://github.com/apache/hive/pull/2321#discussion_r645311896



##########
File path: ql/src/java/org/apache/hadoop/hive/ql/exec/repl/ReplStatsTracker.java
##########
@@ -0,0 +1,132 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hive.ql.exec.repl;
+
+import org.apache.commons.collections4.map.ListOrderedMap;
+import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Tracks the replication statistics per event type.
+ */
+public class ReplStatsTracker {
+
+  // Maintains the descriptive statistics per event type.
+  private HashMap<String, DescriptiveStatistics> descMap;
+
+  // Maintains the top K costliest eventId's
+  private HashMap<String, ListOrderedMap<Long, Long>> topKEvents;

Review comment:
       Changed to ConcurrentHashMap & made addEntry synchronised as well




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] ayushtkn commented on a change in pull request #2321: HIVE-25165. Generate & track statistics per event type for incremental load in replication metrics.

Posted by GitBox <gi...@apache.org>.
ayushtkn commented on a change in pull request #2321:
URL: https://github.com/apache/hive/pull/2321#discussion_r645312328



##########
File path: ql/src/java/org/apache/hadoop/hive/ql/exec/repl/ReplStatsTracker.java
##########
@@ -0,0 +1,132 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hive.ql.exec.repl;
+
+import org.apache.commons.collections4.map.ListOrderedMap;
+import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Tracks the replication statistics per event type.
+ */
+public class ReplStatsTracker {
+
+  // Maintains the descriptive statistics per event type.
+  private HashMap<String, DescriptiveStatistics> descMap;
+
+  // Maintains the top K costliest eventId's
+  private HashMap<String, ListOrderedMap<Long, Long>> topKEvents;
+  // Number of top events to maintain.
+  private final int k;
+
+  public ReplStatsTracker(int k) {
+    this.k = k;
+    descMap = new HashMap<>();
+    topKEvents = new HashMap<>();
+  }
+
+  /**
+   * Adds an entry for tracking.
+   * @param eventType the type of event.
+   * @param eventId the event id.
+   * @param timeTaken time taken to process the event.
+   */
+  public void addEntry(String eventType, String eventId, long timeTaken) {
+    // Update the entry in the descriptive statistics.
+    DescriptiveStatistics descStatistics = descMap.get(eventType);
+    if (descStatistics == null) {
+      descStatistics = new DescriptiveStatistics();
+      descStatistics.addValue(timeTaken);
+      descMap.put(eventType, descStatistics);
+    } else {
+      descStatistics.addValue(timeTaken);
+    }
+
+    // Tracking for top K events, Maintain the list in descending order.
+    ListOrderedMap<Long, Long> topKEntries = topKEvents.get(eventType);
+    if (topKEntries == null) {
+      topKEntries = new ListOrderedMap<>();
+      topKEntries.put(Long.parseLong(eventId), timeTaken);
+      topKEvents.put(eventType, topKEntries);
+    } else {
+      // Get the index of insertion, by descending order.
+      int index = Collections.binarySearch(new ArrayList(topKEntries.values()), timeTaken, Collections.reverseOrder());

Review comment:
       Here itself. :-)
   When the first element the list is sorted(only one element), post that this gives the index where to insert so the list stays sorted, so when I insert the element to the index returned from this, the list stays always sorted.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] ayushtkn commented on a change in pull request #2321: HIVE-25165. Generate & track statistics per event type for incremental load in replication metrics.

Posted by GitBox <gi...@apache.org>.
ayushtkn commented on a change in pull request #2321:
URL: https://github.com/apache/hive/pull/2321#discussion_r645311778



##########
File path: ql/src/java/org/apache/hadoop/hive/ql/parse/repl/ReplLogger.java
##########
@@ -47,4 +48,8 @@ public void dataCopyLog(String message) {
 
   public void setParams(String dbName, String dumpDirectory, long numTables, long numFunctions) {
   }
+
+  public ReplStatsTracker getReplStatsTracker() {

Review comment:
       Added a NoOpReplStatTracker as suggested 

##########
File path: ql/src/java/org/apache/hadoop/hive/ql/parse/repl/metric/event/Stage.java
##########
@@ -35,6 +35,7 @@
   private Map<String, Metric> metrics = new HashMap<>();
   private String errorLogPath;
   private SnapshotUtils.ReplSnapshotCount replSnapshotCount = new SnapshotUtils.ReplSnapshotCount();
+  private String replStats = "";

Review comment:
       Done




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] aasha merged pull request #2321: HIVE-25165. Generate & track statistics per event type for incremental load in replication metrics.

Posted by GitBox <gi...@apache.org>.
aasha merged pull request #2321:
URL: https://github.com/apache/hive/pull/2321


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] aasha commented on a change in pull request #2321: HIVE-25165. Generate & track statistics per event type for incremental load in replication metrics.

Posted by GitBox <gi...@apache.org>.
aasha commented on a change in pull request #2321:
URL: https://github.com/apache/hive/pull/2321#discussion_r643827420



##########
File path: ql/src/java/org/apache/hadoop/hive/ql/parse/repl/ReplLogger.java
##########
@@ -47,4 +48,8 @@ public void dataCopyLog(String message) {
 
   public void setParams(String dbName, String dumpDirectory, long numTables, long numFunctions) {
   }
+
+  public ReplStatsTracker getReplStatsTracker() {

Review comment:
       mark this as abstract

##########
File path: ql/src/java/org/apache/hadoop/hive/ql/exec/repl/ReplStatsTracker.java
##########
@@ -0,0 +1,132 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hive.ql.exec.repl;
+
+import org.apache.commons.collections4.map.ListOrderedMap;
+import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Tracks the replication statistics per event type.
+ */
+public class ReplStatsTracker {
+
+  // Maintains the descriptive statistics per event type.
+  private HashMap<String, DescriptiveStatistics> descMap;
+
+  // Maintains the top K costliest eventId's
+  private HashMap<String, ListOrderedMap<Long, Long>> topKEvents;

Review comment:
       this is not thread safe. check if it can have an impact

##########
File path: ql/src/java/org/apache/hadoop/hive/ql/parse/repl/metric/event/Stage.java
##########
@@ -35,6 +35,7 @@
   private Map<String, Metric> metrics = new HashMap<>();
   private String errorLogPath;
   private SnapshotUtils.ReplSnapshotCount replSnapshotCount = new SnapshotUtils.ReplSnapshotCount();
+  private String replStats = "";

Review comment:
       set to null instead?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] aasha commented on a change in pull request #2321: HIVE-25165. Generate & track statistics per event type for incremental load in replication metrics.

Posted by GitBox <gi...@apache.org>.
aasha commented on a change in pull request #2321:
URL: https://github.com/apache/hive/pull/2321#discussion_r643827420



##########
File path: ql/src/java/org/apache/hadoop/hive/ql/parse/repl/ReplLogger.java
##########
@@ -47,4 +48,8 @@ public void dataCopyLog(String message) {
 
   public void setParams(String dbName, String dumpDirectory, long numTables, long numFunctions) {
   }
+
+  public ReplStatsTracker getReplStatsTracker() {

Review comment:
       mark this as abstract

##########
File path: ql/src/java/org/apache/hadoop/hive/ql/exec/repl/ReplStatsTracker.java
##########
@@ -0,0 +1,132 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hive.ql.exec.repl;
+
+import org.apache.commons.collections4.map.ListOrderedMap;
+import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Tracks the replication statistics per event type.
+ */
+public class ReplStatsTracker {
+
+  // Maintains the descriptive statistics per event type.
+  private HashMap<String, DescriptiveStatistics> descMap;
+
+  // Maintains the top K costliest eventId's
+  private HashMap<String, ListOrderedMap<Long, Long>> topKEvents;

Review comment:
       this is not thread safe. check if it can have an impact

##########
File path: ql/src/java/org/apache/hadoop/hive/ql/parse/repl/metric/event/Stage.java
##########
@@ -35,6 +35,7 @@
   private Map<String, Metric> metrics = new HashMap<>();
   private String errorLogPath;
   private SnapshotUtils.ReplSnapshotCount replSnapshotCount = new SnapshotUtils.ReplSnapshotCount();
+  private String replStats = "";

Review comment:
       set to null instead?

##########
File path: ql/src/java/org/apache/hadoop/hive/ql/exec/repl/ReplStatsTracker.java
##########
@@ -0,0 +1,132 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hive.ql.exec.repl;
+
+import org.apache.commons.collections4.map.ListOrderedMap;
+import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Tracks the replication statistics per event type.
+ */
+public class ReplStatsTracker {
+
+  // Maintains the descriptive statistics per event type.
+  private HashMap<String, DescriptiveStatistics> descMap;
+
+  // Maintains the top K costliest eventId's
+  private HashMap<String, ListOrderedMap<Long, Long>> topKEvents;
+  // Number of top events to maintain.
+  private final int k;
+
+  public ReplStatsTracker(int k) {
+    this.k = k;
+    descMap = new HashMap<>();
+    topKEvents = new HashMap<>();
+  }
+
+  /**
+   * Adds an entry for tracking.
+   * @param eventType the type of event.
+   * @param eventId the event id.
+   * @param timeTaken time taken to process the event.
+   */
+  public void addEntry(String eventType, String eventId, long timeTaken) {
+    // Update the entry in the descriptive statistics.
+    DescriptiveStatistics descStatistics = descMap.get(eventType);
+    if (descStatistics == null) {
+      descStatistics = new DescriptiveStatistics();
+      descStatistics.addValue(timeTaken);
+      descMap.put(eventType, descStatistics);
+    } else {
+      descStatistics.addValue(timeTaken);
+    }
+
+    // Tracking for top K events, Maintain the list in descending order.
+    ListOrderedMap<Long, Long> topKEntries = topKEvents.get(eventType);
+    if (topKEntries == null) {
+      topKEntries = new ListOrderedMap<>();
+      topKEntries.put(Long.parseLong(eventId), timeTaken);
+      topKEvents.put(eventType, topKEntries);
+    } else {
+      // Get the index of insertion, by descending order.
+      int index = Collections.binarySearch(new ArrayList(topKEntries.values()), timeTaken, Collections.reverseOrder());

Review comment:
       where are you sorting this?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] ayushtkn commented on a change in pull request #2321: HIVE-25165. Generate & track statistics per event type for incremental load in replication metrics.

Posted by GitBox <gi...@apache.org>.
ayushtkn commented on a change in pull request #2321:
URL: https://github.com/apache/hive/pull/2321#discussion_r645311778



##########
File path: ql/src/java/org/apache/hadoop/hive/ql/parse/repl/ReplLogger.java
##########
@@ -47,4 +48,8 @@ public void dataCopyLog(String message) {
 
   public void setParams(String dbName, String dumpDirectory, long numTables, long numFunctions) {
   }
+
+  public ReplStatsTracker getReplStatsTracker() {

Review comment:
       Added a NoOpReplStatTracker as suggested 

##########
File path: ql/src/java/org/apache/hadoop/hive/ql/parse/repl/metric/event/Stage.java
##########
@@ -35,6 +35,7 @@
   private Map<String, Metric> metrics = new HashMap<>();
   private String errorLogPath;
   private SnapshotUtils.ReplSnapshotCount replSnapshotCount = new SnapshotUtils.ReplSnapshotCount();
+  private String replStats = "";

Review comment:
       Done

##########
File path: ql/src/java/org/apache/hadoop/hive/ql/exec/repl/ReplStatsTracker.java
##########
@@ -0,0 +1,132 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hive.ql.exec.repl;
+
+import org.apache.commons.collections4.map.ListOrderedMap;
+import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Tracks the replication statistics per event type.
+ */
+public class ReplStatsTracker {
+
+  // Maintains the descriptive statistics per event type.
+  private HashMap<String, DescriptiveStatistics> descMap;
+
+  // Maintains the top K costliest eventId's
+  private HashMap<String, ListOrderedMap<Long, Long>> topKEvents;

Review comment:
       Changed to ConcurrentHashMap & made addEntry synchronised as well

##########
File path: ql/src/java/org/apache/hadoop/hive/ql/exec/repl/ReplStatsTracker.java
##########
@@ -0,0 +1,132 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hive.ql.exec.repl;
+
+import org.apache.commons.collections4.map.ListOrderedMap;
+import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Tracks the replication statistics per event type.
+ */
+public class ReplStatsTracker {
+
+  // Maintains the descriptive statistics per event type.
+  private HashMap<String, DescriptiveStatistics> descMap;
+
+  // Maintains the top K costliest eventId's
+  private HashMap<String, ListOrderedMap<Long, Long>> topKEvents;
+  // Number of top events to maintain.
+  private final int k;
+
+  public ReplStatsTracker(int k) {
+    this.k = k;
+    descMap = new HashMap<>();
+    topKEvents = new HashMap<>();
+  }
+
+  /**
+   * Adds an entry for tracking.
+   * @param eventType the type of event.
+   * @param eventId the event id.
+   * @param timeTaken time taken to process the event.
+   */
+  public void addEntry(String eventType, String eventId, long timeTaken) {
+    // Update the entry in the descriptive statistics.
+    DescriptiveStatistics descStatistics = descMap.get(eventType);
+    if (descStatistics == null) {
+      descStatistics = new DescriptiveStatistics();
+      descStatistics.addValue(timeTaken);
+      descMap.put(eventType, descStatistics);
+    } else {
+      descStatistics.addValue(timeTaken);
+    }
+
+    // Tracking for top K events, Maintain the list in descending order.
+    ListOrderedMap<Long, Long> topKEntries = topKEvents.get(eventType);
+    if (topKEntries == null) {
+      topKEntries = new ListOrderedMap<>();
+      topKEntries.put(Long.parseLong(eventId), timeTaken);
+      topKEvents.put(eventType, topKEntries);
+    } else {
+      // Get the index of insertion, by descending order.
+      int index = Collections.binarySearch(new ArrayList(topKEntries.values()), timeTaken, Collections.reverseOrder());

Review comment:
       Here itself. :-)
   When the first element the list is sorted(only one element), post that this gives the index where to insert so the list stays sorted, so when I insert the element to the index returned from this, the list stays always sorted.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] aasha commented on a change in pull request #2321: HIVE-25165. Generate & track statistics per event type for incremental load in replication metrics.

Posted by GitBox <gi...@apache.org>.
aasha commented on a change in pull request #2321:
URL: https://github.com/apache/hive/pull/2321#discussion_r644714176



##########
File path: ql/src/java/org/apache/hadoop/hive/ql/exec/repl/ReplStatsTracker.java
##########
@@ -0,0 +1,132 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hive.ql.exec.repl;
+
+import org.apache.commons.collections4.map.ListOrderedMap;
+import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Tracks the replication statistics per event type.
+ */
+public class ReplStatsTracker {
+
+  // Maintains the descriptive statistics per event type.
+  private HashMap<String, DescriptiveStatistics> descMap;
+
+  // Maintains the top K costliest eventId's
+  private HashMap<String, ListOrderedMap<Long, Long>> topKEvents;
+  // Number of top events to maintain.
+  private final int k;
+
+  public ReplStatsTracker(int k) {
+    this.k = k;
+    descMap = new HashMap<>();
+    topKEvents = new HashMap<>();
+  }
+
+  /**
+   * Adds an entry for tracking.
+   * @param eventType the type of event.
+   * @param eventId the event id.
+   * @param timeTaken time taken to process the event.
+   */
+  public void addEntry(String eventType, String eventId, long timeTaken) {
+    // Update the entry in the descriptive statistics.
+    DescriptiveStatistics descStatistics = descMap.get(eventType);
+    if (descStatistics == null) {
+      descStatistics = new DescriptiveStatistics();
+      descStatistics.addValue(timeTaken);
+      descMap.put(eventType, descStatistics);
+    } else {
+      descStatistics.addValue(timeTaken);
+    }
+
+    // Tracking for top K events, Maintain the list in descending order.
+    ListOrderedMap<Long, Long> topKEntries = topKEvents.get(eventType);
+    if (topKEntries == null) {
+      topKEntries = new ListOrderedMap<>();
+      topKEntries.put(Long.parseLong(eventId), timeTaken);
+      topKEvents.put(eventType, topKEntries);
+    } else {
+      // Get the index of insertion, by descending order.
+      int index = Collections.binarySearch(new ArrayList(topKEntries.values()), timeTaken, Collections.reverseOrder());

Review comment:
       where are you sorting this?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org