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:
parent
e9aaf12f6e
commit
1a6834c8c9
|
@ -351,7 +351,7 @@ public class CacheConfig {
|
||||||
StringUtils.humanReadableInt(cacheSize));
|
StringUtils.humanReadableInt(cacheSize));
|
||||||
if (offHeapCacheSize <= 0) {
|
if (offHeapCacheSize <= 0) {
|
||||||
globalBlockCache = new LruBlockCache(cacheSize,
|
globalBlockCache = new LruBlockCache(cacheSize,
|
||||||
StoreFile.DEFAULT_BLOCKSIZE_SMALL);
|
StoreFile.DEFAULT_BLOCKSIZE_SMALL, conf);
|
||||||
} else {
|
} else {
|
||||||
globalBlockCache = new DoubleBlockCache(cacheSize, offHeapCacheSize,
|
globalBlockCache = new DoubleBlockCache(cacheSize, offHeapCacheSize,
|
||||||
StoreFile.DEFAULT_BLOCKSIZE_SMALL, blockSize, conf);
|
StoreFile.DEFAULT_BLOCKSIZE_SMALL, blockSize, conf);
|
||||||
|
|
|
@ -67,7 +67,7 @@ public class DoubleBlockCache implements BlockCache, HeapSize {
|
||||||
+ StringUtils.humanReadableInt(onHeapSize)
|
+ StringUtils.humanReadableInt(onHeapSize)
|
||||||
+ "bytes with an average block size of "
|
+ "bytes with an average block size of "
|
||||||
+ StringUtils.humanReadableInt(onHeapBlockSize) + " bytes.");
|
+ StringUtils.humanReadableInt(onHeapBlockSize) + " bytes.");
|
||||||
onHeapCache = new LruBlockCache(onHeapSize, onHeapBlockSize);
|
onHeapCache = new LruBlockCache(onHeapSize, onHeapBlockSize, conf);
|
||||||
|
|
||||||
LOG.info("Creating off-heap cache of size "
|
LOG.info("Creating off-heap cache of size "
|
||||||
+ StringUtils.humanReadableInt(offHeapSize)
|
+ StringUtils.humanReadableInt(offHeapSize)
|
||||||
|
|
|
@ -99,14 +99,15 @@ public class LruBlockCache implements BlockCache, HeapSize {
|
||||||
static final Log LOG = LogFactory.getLog(LruBlockCache.class);
|
static final Log LOG = LogFactory.getLog(LruBlockCache.class);
|
||||||
|
|
||||||
/** Default Configuration Parameters*/
|
/** Default Configuration Parameters*/
|
||||||
|
static final String LRU_MIN_FACTOR = "hbase.lru.blockcache.min.factor";
|
||||||
|
|
||||||
/** Backing Concurrent Map Configuration */
|
/** Backing Concurrent Map Configuration */
|
||||||
static final float DEFAULT_LOAD_FACTOR = 0.75f;
|
static final float DEFAULT_LOAD_FACTOR = 0.75f;
|
||||||
static final int DEFAULT_CONCURRENCY_LEVEL = 16;
|
static final int DEFAULT_CONCURRENCY_LEVEL = 16;
|
||||||
|
|
||||||
/** Eviction thresholds */
|
/** Eviction thresholds */
|
||||||
static final float DEFAULT_MIN_FACTOR = 0.75f;
|
static final float DEFAULT_MIN_FACTOR = 0.95f;
|
||||||
static final float DEFAULT_ACCEPTABLE_FACTOR = 0.85f;
|
static final float DEFAULT_ACCEPTABLE_FACTOR = 0.99f;
|
||||||
|
|
||||||
/** Priority buckets */
|
/** Priority buckets */
|
||||||
static final float DEFAULT_SINGLE_FACTOR = 0.25f;
|
static final float DEFAULT_SINGLE_FACTOR = 0.25f;
|
||||||
|
@ -197,6 +198,22 @@ public class LruBlockCache implements BlockCache, HeapSize {
|
||||||
DEFAULT_MEMORY_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.
|
* Configurable constructor. Use this constructor if not using defaults.
|
||||||
* @param maxSize maximum size of this cache, in bytes
|
* @param maxSize maximum size of this cache, in bytes
|
||||||
|
|
|
@ -200,10 +200,9 @@ public class TestLruBlockCache {
|
||||||
assertTrue(cache.heapSize() <
|
assertTrue(cache.heapSize() <
|
||||||
(maxSize * LruBlockCache.DEFAULT_ACCEPTABLE_FACTOR));
|
(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[0].cacheKey, true) == null);
|
||||||
assertTrue(cache.getBlock(blocks[1].cacheKey, true) == null);
|
for(int i=1;i<blocks.length;i++) {
|
||||||
for(int i=2;i<blocks.length;i++) {
|
|
||||||
assertEquals(cache.getBlock(blocks[i].cacheKey, true),
|
assertEquals(cache.getBlock(blocks[i].cacheKey, true),
|
||||||
blocks[i]);
|
blocks[i]);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue