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
This commit is contained in:
Zhihong Yu 2012-07-19 18:38:52 +00:00
parent e9aaf12f6e
commit 1a6834c8c9
4 changed files with 24 additions and 8 deletions

View File

@ -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);

View File

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

View File

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

View File

@ -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<blocks.length;i++) {
for(int i=1;i<blocks.length;i++) {
assertEquals(cache.getBlock(blocks[i].cacheKey, true),
blocks[i]);
}