From 1a6834c8c97427f1f2a18ffb190e43ec90be8ce7 Mon Sep 17 00:00:00 2001 From: Zhihong Yu Date: Thu, 19 Jul 2012 18:38:52 +0000 Subject: [PATCH] HBASE-6312 Make BlockCache eviction thresholds configurable (Jie Huang) git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1363468 13f79535-47bb-0310-9956-ffa450edef68 --- .../hadoop/hbase/io/hfile/CacheConfig.java | 2 +- .../hbase/io/hfile/DoubleBlockCache.java | 2 +- .../hadoop/hbase/io/hfile/LruBlockCache.java | 23 ++++++++++++++++--- .../hbase/io/hfile/TestLruBlockCache.java | 5 ++-- 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/CacheConfig.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/CacheConfig.java index e5e5fc7d44c..44599dd572c 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/CacheConfig.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/CacheConfig.java @@ -351,7 +351,7 @@ public class CacheConfig { StringUtils.humanReadableInt(cacheSize)); if (offHeapCacheSize <= 0) { globalBlockCache = new LruBlockCache(cacheSize, - StoreFile.DEFAULT_BLOCKSIZE_SMALL); + StoreFile.DEFAULT_BLOCKSIZE_SMALL, conf); } else { globalBlockCache = new DoubleBlockCache(cacheSize, offHeapCacheSize, StoreFile.DEFAULT_BLOCKSIZE_SMALL, blockSize, conf); diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/DoubleBlockCache.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/DoubleBlockCache.java index e952ef9bda1..a8d8075f307 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/DoubleBlockCache.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/DoubleBlockCache.java @@ -67,7 +67,7 @@ public class DoubleBlockCache implements BlockCache, HeapSize { + StringUtils.humanReadableInt(onHeapSize) + "bytes with an average block size of " + StringUtils.humanReadableInt(onHeapBlockSize) + " bytes."); - onHeapCache = new LruBlockCache(onHeapSize, onHeapBlockSize); + onHeapCache = new LruBlockCache(onHeapSize, onHeapBlockSize, conf); LOG.info("Creating off-heap cache of size " + StringUtils.humanReadableInt(offHeapSize) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/LruBlockCache.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/LruBlockCache.java index 49b49514c50..3ff6d6078f3 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/LruBlockCache.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/LruBlockCache.java @@ -99,14 +99,15 @@ public class LruBlockCache implements BlockCache, HeapSize { static final Log LOG = LogFactory.getLog(LruBlockCache.class); /** Default Configuration Parameters*/ - + static final String LRU_MIN_FACTOR = "hbase.lru.blockcache.min.factor"; + /** Backing Concurrent Map Configuration */ static final float DEFAULT_LOAD_FACTOR = 0.75f; static final int DEFAULT_CONCURRENCY_LEVEL = 16; /** Eviction thresholds */ - static final float DEFAULT_MIN_FACTOR = 0.75f; - static final float DEFAULT_ACCEPTABLE_FACTOR = 0.85f; + static final float DEFAULT_MIN_FACTOR = 0.95f; + static final float DEFAULT_ACCEPTABLE_FACTOR = 0.99f; /** Priority buckets */ static final float DEFAULT_SINGLE_FACTOR = 0.25f; @@ -196,6 +197,22 @@ public class LruBlockCache implements BlockCache, HeapSize { DEFAULT_SINGLE_FACTOR, DEFAULT_MULTI_FACTOR, DEFAULT_MEMORY_FACTOR); } + + public LruBlockCache(long maxSize, long blockSize, boolean evictionThread, Configuration conf) { + this(maxSize, blockSize, evictionThread, + (int)Math.ceil(1.2*maxSize/blockSize), + DEFAULT_LOAD_FACTOR, + DEFAULT_CONCURRENCY_LEVEL, + conf.getFloat(LRU_MIN_FACTOR, DEFAULT_MIN_FACTOR), + DEFAULT_ACCEPTABLE_FACTOR, + DEFAULT_SINGLE_FACTOR, + DEFAULT_MULTI_FACTOR, + DEFAULT_MEMORY_FACTOR); + } + + public LruBlockCache(long maxSize, long blockSize, Configuration conf) { + this(maxSize, blockSize, true, conf); + } /** * Configurable constructor. Use this constructor if not using defaults. diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestLruBlockCache.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestLruBlockCache.java index c301c0c3a01..37e0d5214be 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestLruBlockCache.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestLruBlockCache.java @@ -200,10 +200,9 @@ public class TestLruBlockCache { assertTrue(cache.heapSize() < (maxSize * LruBlockCache.DEFAULT_ACCEPTABLE_FACTOR)); - // All blocks except block 0 and 1 should be in the cache + // All blocks except block 0 should be in the cache assertTrue(cache.getBlock(blocks[0].cacheKey, true) == null); - assertTrue(cache.getBlock(blocks[1].cacheKey, true) == null); - for(int i=2;i