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 2019/06/24 16:17:54 UTC

[GitHub] [hive] odraese commented on a change in pull request #683: HIVE-21846: Create a thread in TezAM which periodically fetches LlapDaemon metrics

odraese commented on a change in pull request #683: HIVE-21846: Create a thread in TezAM which periodically fetches LlapDaemon metrics
URL: https://github.com/apache/hive/pull/683#discussion_r296801109
 
 

 ##########
 File path: llap-tez/src/java/org/apache/hadoop/hive/llap/tezplugins/metrics/LlapMetricsCollector.java
 ##########
 @@ -0,0 +1,194 @@
+/*
+ * Licensed 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.llap.tezplugins.metrics;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
+import com.google.protobuf.ServiceException;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hive.conf.HiveConf;
+import org.apache.hadoop.hive.llap.daemon.rpc.LlapDaemonProtocolProtos;
+import org.apache.hadoop.hive.llap.impl.LlapManagementProtocolClientImpl;
+import org.apache.hadoop.hive.llap.registry.LlapServiceInstance;
+import org.apache.hadoop.hive.registry.ServiceInstanceStateChangeListener;
+import org.apache.hadoop.io.retry.RetryPolicies;
+import org.apache.hadoop.io.retry.RetryPolicy;
+import org.apache.hadoop.net.NetUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.net.SocketFactory;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Collect metrics from the llap daemons in every given milliseconds.
+ */
+public class LlapMetricsCollector implements ServiceInstanceStateChangeListener<LlapServiceInstance> {
+
+  private static final Logger LOG = LoggerFactory.getLogger(LlapMetricsCollector.class);
+  private static final String THREAD_NAME = "LlapTaskSchedulerMetricsCollectorThread";
+  private static final long INITIAL_DELAY_MSEC = 60000L;
+
+  private final Configuration conf;
+  private final ScheduledExecutorService scheduledMetricsExecutor;
+  private final LlapManagementProtocolClientImplFactory clientFactory;
+  private final Map<String, LlapManagementProtocolClientImpl> llapClients;
+  private final Map<String, LlapMetrics> instanceStatisticsMap;
+  private final long metricsCollectionMs;
+
+
+  public LlapMetricsCollector(Configuration conf) {
+    this(
+            conf,
+            Executors.newSingleThreadScheduledExecutor(
+                    new ThreadFactoryBuilder().setDaemon(true).setNameFormat(THREAD_NAME)
+                            .build()),
+            LlapManagementProtocolClientImplFactory.basicInstance(conf));
+  }
+
+  @VisibleForTesting
+  LlapMetricsCollector(Configuration conf, ScheduledExecutorService scheduledMetricsExecutor,
+                       LlapManagementProtocolClientImplFactory clientFactory) {
+    this.conf = conf;
+    this.scheduledMetricsExecutor = scheduledMetricsExecutor;
+    this.clientFactory = clientFactory;
+    this.llapClients = new HashMap<>();
+    this.instanceStatisticsMap = new ConcurrentHashMap<>();
+    this.metricsCollectionMs = HiveConf.getTimeVar(conf,
+            HiveConf.ConfVars.LLAP_TASK_SCHEDULER_AM_COLLECT_DAEMON_METRICS_MS, TimeUnit.MILLISECONDS);
+  }
+
+  public void start() {
+    if (enabled()) {
+      scheduledMetricsExecutor.scheduleAtFixedRate(() -> {
+        collectMetrics();
+      }, INITIAL_DELAY_MSEC, metricsCollectionMs, TimeUnit.MILLISECONDS);
+    }
+  }
+
+  private boolean enabled() {
+    return metricsCollectionMs > 0;
+  }
+
+  public void shutdown() {
+    scheduledMetricsExecutor.shutdownNow();
+  }
+
+  @VisibleForTesting
+  void collectMetrics() {
+    if (enabled()) {
+      for (Map.Entry<String, LlapManagementProtocolClientImpl> entry : llapClients.entrySet()) {
+        String identity = entry.getKey();
+        LlapManagementProtocolClientImpl client = entry.getValue();
+        try {
+          LlapDaemonProtocolProtos.GetDaemonMetricsResponseProto metrics =
+                  client.getDaemonMetrics(null,
+                          LlapDaemonProtocolProtos.GetDaemonMetricsRequestProto.newBuilder().build());
+          instanceStatisticsMap.put(identity, new LlapMetrics(metrics));
+
+        } catch (ServiceException ex) {
+          LOG.error(ex.getMessage(), ex);
 
 Review comment:
   Should we maybe remove the previously stored metrics from instanceStatisticsMap? I know, we have an associated timestamp there but it would make the code "safer" if we don't store old metrics whenever an error happens when we try to receive new daemon metrics.

----------------------------------------------------------------
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


With regards,
Apache Git Services

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