Repository: kylin Updated Branches: refs/heads/master c79c59f88 -> 86f7149fc
KYLIN-1676: High CPU in TrieDictionary due to incorrect use of HashMap Project: http://git-wip-us.apache.org/repos/asf/kylin/repo Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/86f7149f Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/86f7149f Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/86f7149f Branch: refs/heads/master Commit: 86f7149fc809203b45d1b0cb74c2f00a45082ba2 Parents: c79c59f Author: Ma Gang <mg4w...@163.com> Authored: Thu May 26 21:59:33 2016 +0800 Committer: Zhong <yangzh...@lm-shc-16501214.corp.ebay.com> Committed: Thu May 26 22:08:58 2016 +0800 ---------------------------------------------------------------------- .../src/main/java/org/apache/kylin/dict/TrieDictionary.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/kylin/blob/86f7149f/core-dictionary/src/main/java/org/apache/kylin/dict/TrieDictionary.java ---------------------------------------------------------------------- diff --git a/core-dictionary/src/main/java/org/apache/kylin/dict/TrieDictionary.java b/core-dictionary/src/main/java/org/apache/kylin/dict/TrieDictionary.java index 552aa92..5cf672f 100644 --- a/core-dictionary/src/main/java/org/apache/kylin/dict/TrieDictionary.java +++ b/core-dictionary/src/main/java/org/apache/kylin/dict/TrieDictionary.java @@ -31,7 +31,9 @@ import java.io.*; import java.lang.ref.SoftReference; import java.util.Arrays; import java.util.HashMap; +import java.util.Map; import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; /** * A dictionary based on Trie data structure that maps enumerations of byte[] to @@ -75,7 +77,7 @@ public class TrieDictionary<T> extends Dictionary<T> { transient private int firstByteOffset; transient private boolean enableValueCache = true; - transient private SoftReference<HashMap> valueToIdCache; + transient private SoftReference<Map> valueToIdCache; transient private SoftReference<Object[]> idToValueCache; transient private boolean enableIdToValueBytesCache = false; @@ -119,7 +121,7 @@ public class TrieDictionary<T> extends Dictionary<T> { } if (enableValueCache) { - valueToIdCache = new SoftReference<HashMap>(new HashMap()); + valueToIdCache = new SoftReference<Map>(new ConcurrentHashMap()); idToValueCache = new SoftReference<Object[]>(new Object[nValues]); } } @@ -147,7 +149,7 @@ public class TrieDictionary<T> extends Dictionary<T> { @Override final protected int getIdFromValueImpl(T value, int roundingFlag) { if (enableValueCache && roundingFlag == 0) { - HashMap cache = valueToIdCache.get(); // SoftReference to skip cache gracefully when short of memory + Map cache = valueToIdCache.get(); // SoftReference to skip cache gracefully when short of memory if (cache != null) { Integer id = null; id = (Integer) cache.get(value);