From 68164b197b4619235fa46bf5600e6fe815ef1410 Mon Sep 17 00:00:00 2001 From: Jing Zhao Date: Fri, 20 Dec 2013 22:08:53 +0000 Subject: [PATCH] HADOOP-10169. Merge change r1552820 from trunk. git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1552822 13f79535-47bb-0310-9956-ffa450edef68 --- .../hadoop-common/CHANGES.txt | 3 +++ .../hadoop/metrics2/source/JvmMetrics.java | 19 +++++++++++-------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index 2b4fa3462eb..67c6d700505 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -109,6 +109,9 @@ Release 2.4.0 - UNRELEASED HADOOP-10164. Allow UGI to login with a known Subject (bobby) + HADOOP-10169. Remove the unnecessary synchronized in JvmMetrics class. + (Liang Xie via jing9) + OPTIMIZATIONS HADOOP-9748. Reduce blocking on UGI.ensureInitialized (daryn) diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/source/JvmMetrics.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/source/JvmMetrics.java index 35c92bbe92c..750499139a6 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/source/JvmMetrics.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/source/JvmMetrics.java @@ -24,10 +24,8 @@ import java.lang.management.MemoryUsage; import java.lang.management.ThreadInfo; import java.lang.management.ThreadMXBean; import java.lang.management.GarbageCollectorMXBean; -import java.util.Map; import java.util.List; - -import com.google.common.collect.Maps; +import java.util.concurrent.ConcurrentHashMap; import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.log.metrics.EventCounter; @@ -67,7 +65,8 @@ public class JvmMetrics implements MetricsSource { ManagementFactory.getGarbageCollectorMXBeans(); final ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean(); final String processName, sessionId; - final Map gcInfoCache = Maps.newHashMap(); + final ConcurrentHashMap gcInfoCache = + new ConcurrentHashMap(); JvmMetrics(String processName, String sessionId) { this.processName = processName; @@ -123,13 +122,17 @@ public class JvmMetrics implements MetricsSource { .addCounter(GcTimeMillis, timeMillis); } - private synchronized MetricsInfo[] getGcInfo(String gcName) { + private MetricsInfo[] getGcInfo(String gcName) { MetricsInfo[] gcInfo = gcInfoCache.get(gcName); if (gcInfo == null) { gcInfo = new MetricsInfo[2]; - gcInfo[0] = Interns.info("GcCount"+ gcName, "GC Count for "+ gcName); - gcInfo[1] = Interns.info("GcTimeMillis"+ gcName, "GC Time for "+ gcName); - gcInfoCache.put(gcName, gcInfo); + gcInfo[0] = Interns.info("GcCount" + gcName, "GC Count for " + gcName); + gcInfo[1] = Interns + .info("GcTimeMillis" + gcName, "GC Time for " + gcName); + MetricsInfo[] previousGcInfo = gcInfoCache.putIfAbsent(gcName, gcInfo); + if (previousGcInfo != null) { + return previousGcInfo; + } } return gcInfo; }