diff --git llap-server/src/java/org/apache/hadoop/hive/llap/metrics/LlapDaemonExecutorMetrics.java llap-server/src/java/org/apache/hadoop/hive/llap/metrics/LlapDaemonExecutorMetrics.java index 1110683..ecb83bc 100644 --- llap-server/src/java/org/apache/hadoop/hive/llap/metrics/LlapDaemonExecutorMetrics.java +++ llap-server/src/java/org/apache/hadoop/hive/llap/metrics/LlapDaemonExecutorMetrics.java @@ -48,8 +48,10 @@ import java.lang.management.ThreadInfo; import java.lang.management.ThreadMXBean; import java.util.Map; +import java.util.Set; import java.util.concurrent.ConcurrentHashMap; +import com.google.common.collect.Sets; import org.apache.hadoop.hive.llap.daemon.impl.ContainerRunnerImpl; import org.apache.hadoop.metrics2.MetricsCollector; import org.apache.hadoop.metrics2.MetricsInfo; @@ -82,6 +84,8 @@ private long maxTimeLost = Long.MIN_VALUE; private long maxTimeToKill = Long.MIN_VALUE; + private final Set executorNames; + final MutableGaugeLong[] executorThreadCpuTime; final MutableGaugeLong[] executorThreadUserTime; @Metric @@ -152,6 +156,7 @@ private LlapDaemonExecutorMetrics(String displayName, JvmMetrics jm, String sess "ops", "latency", interval); } + this.executorNames = Sets.newHashSet(); for (int i = 0; i < numExecutors; i++) { MetricsInfo mic = new LlapDaemonCustomMetricsInfo(ExecutorThreadCPUTime.name() + "_" + i, ExecutorThreadCPUTime.description()); @@ -161,6 +166,7 @@ private LlapDaemonExecutorMetrics(String displayName, JvmMetrics jm, String sess this.userMetricsInfoMap.put(i, miu); this.executorThreadCpuTime[i] = registry.newGauge(mic, 0L); this.executorThreadUserTime[i] = registry.newGauge(miu, 0L); + this.executorNames.add(ContainerRunnerImpl.THREAD_NAME_FORMAT_PREFIX + i); } } @@ -304,10 +310,13 @@ private void updateThreadMetrics(MetricsRecordBuilder rb) { final ThreadInfo[] infos = threadMXBean.getThreadInfo(ids); for (int i = 0; i < ids.length; i++) { ThreadInfo threadInfo = infos[i]; + if (threadInfo == null) { + continue; + } String threadName = threadInfo.getThreadName(); long threadId = ids[i]; for (int j = 0; j < numExecutors; j++) { - if (threadName.equals(ContainerRunnerImpl.THREAD_NAME_FORMAT_PREFIX + j)) { + if (executorNames.contains(threadName)) { executorThreadCpuTime[j].set(threadMXBean.getThreadCpuTime(threadId)); executorThreadUserTime[j].set(threadMXBean.getThreadUserTime(threadId)); }