HBASE-18652 Expose individual cache stats in a CombinedCache through JMX
Signed-off-by: tedyu <yuzhihong@gmail.com>
This commit is contained in:
parent
5de4a7d898
commit
5bfe1da984
|
@ -345,6 +345,23 @@ public interface MetricsRegionServerSource extends BaseSource, JvmPauseMonitorSo
|
||||||
String BLOCK_CACHE_DELETE_FAMILY_BLOOM_HIT_COUNT = "blockCacheDeleteFamilyBloomHitCount";
|
String BLOCK_CACHE_DELETE_FAMILY_BLOOM_HIT_COUNT = "blockCacheDeleteFamilyBloomHitCount";
|
||||||
String BLOCK_CACHE_TRAILER_HIT_COUNT = "blockCacheTrailerHitCount";
|
String BLOCK_CACHE_TRAILER_HIT_COUNT = "blockCacheTrailerHitCount";
|
||||||
|
|
||||||
|
String L1_CACHE_HIT_COUNT = "l1CacheHitCount";
|
||||||
|
String L1_CACHE_HIT_COUNT_DESC = "L1 cache hit count.";
|
||||||
|
String L1_CACHE_MISS_COUNT = "l1CacheMissCount";
|
||||||
|
String L1_CACHE_MISS_COUNT_DESC = "L1 cache miss count.";
|
||||||
|
String L1_CACHE_HIT_RATIO = "l1CacheHitRatio";
|
||||||
|
String L1_CACHE_HIT_RATIO_DESC = "L1 cache hit ratio.";
|
||||||
|
String L1_CACHE_MISS_RATIO = "l1CacheMissRatio";
|
||||||
|
String L1_CACHE_MISS_RATIO_DESC = "L1 cache miss ratio.";
|
||||||
|
String L2_CACHE_HIT_COUNT = "l2CacheHitCount";
|
||||||
|
String L2_CACHE_HIT_COUNT_DESC = "L2 cache hit count.";
|
||||||
|
String L2_CACHE_MISS_COUNT = "l2CacheMissCount";
|
||||||
|
String L2_CACHE_MISS_COUNT_DESC = "L2 cache miss count.";
|
||||||
|
String L2_CACHE_HIT_RATIO = "l2CacheHitRatio";
|
||||||
|
String L2_CACHE_HIT_RATIO_DESC = "L2 cache hit ratio.";
|
||||||
|
String L2_CACHE_MISS_RATIO = "l2CacheMissRatio";
|
||||||
|
String L2_CACHE_MISS_RATIO_DESC = "L2 cache miss ratio.";
|
||||||
|
|
||||||
String RS_START_TIME_NAME = "regionServerStartTime";
|
String RS_START_TIME_NAME = "regionServerStartTime";
|
||||||
String ZOOKEEPER_QUORUM_NAME = "zookeeperQuorum";
|
String ZOOKEEPER_QUORUM_NAME = "zookeeperQuorum";
|
||||||
String SERVER_NAME_NAME = "serverName";
|
String SERVER_NAME_NAME = "serverName";
|
||||||
|
|
|
@ -258,6 +258,46 @@ public interface MetricsRegionServerWrapper {
|
||||||
*/
|
*/
|
||||||
long getBlockCacheFailedInsertions();
|
long getBlockCacheFailedInsertions();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hit count of L1 cache.
|
||||||
|
*/
|
||||||
|
public long getL1CacheHitCount();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Miss count of L1 cache.
|
||||||
|
*/
|
||||||
|
public long getL1CacheMissCount();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hit ratio of L1 cache.
|
||||||
|
*/
|
||||||
|
public double getL1CacheHitRatio();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Miss ratio of L1 cache.
|
||||||
|
*/
|
||||||
|
public double getL1CacheMissRatio();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hit count of L2 cache.
|
||||||
|
*/
|
||||||
|
public long getL2CacheHitCount();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Miss count of L2 cache.
|
||||||
|
*/
|
||||||
|
public long getL2CacheMissCount();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hit ratio of L2 cache.
|
||||||
|
*/
|
||||||
|
public double getL2CacheHitRatio();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Miss ratio of L2 cache.
|
||||||
|
*/
|
||||||
|
public double getL2CacheMissRatio();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Force a re-computation of the metrics.
|
* Force a re-computation of the metrics.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -458,6 +458,22 @@ public class MetricsRegionServerSourceImpl
|
||||||
.addCounter(Interns.info(BLOCK_CACHE_DELETE_FAMILY_BLOOM_HIT_COUNT, ""),
|
.addCounter(Interns.info(BLOCK_CACHE_DELETE_FAMILY_BLOOM_HIT_COUNT, ""),
|
||||||
rsWrap.getDeleteFamilyBloomHitCount())
|
rsWrap.getDeleteFamilyBloomHitCount())
|
||||||
.addCounter(Interns.info(BLOCK_CACHE_TRAILER_HIT_COUNT, ""), rsWrap.getTrailerHitCount())
|
.addCounter(Interns.info(BLOCK_CACHE_TRAILER_HIT_COUNT, ""), rsWrap.getTrailerHitCount())
|
||||||
|
.addGauge(Interns.info(L1_CACHE_HIT_COUNT, L1_CACHE_HIT_COUNT_DESC),
|
||||||
|
rsWrap.getL1CacheHitCount())
|
||||||
|
.addGauge(Interns.info(L1_CACHE_MISS_COUNT, L1_CACHE_MISS_COUNT_DESC),
|
||||||
|
rsWrap.getL1CacheMissCount())
|
||||||
|
.addGauge(Interns.info(L1_CACHE_HIT_RATIO, L1_CACHE_HIT_RATIO_DESC),
|
||||||
|
rsWrap.getL1CacheHitRatio())
|
||||||
|
.addGauge(Interns.info(L1_CACHE_MISS_RATIO, L1_CACHE_MISS_RATIO_DESC),
|
||||||
|
rsWrap.getL1CacheMissRatio())
|
||||||
|
.addGauge(Interns.info(L2_CACHE_HIT_COUNT, L2_CACHE_HIT_COUNT_DESC),
|
||||||
|
rsWrap.getL2CacheHitCount())
|
||||||
|
.addGauge(Interns.info(L2_CACHE_MISS_COUNT, L2_CACHE_MISS_COUNT_DESC),
|
||||||
|
rsWrap.getL2CacheMissCount())
|
||||||
|
.addGauge(Interns.info(L2_CACHE_HIT_RATIO, L2_CACHE_HIT_RATIO_DESC),
|
||||||
|
rsWrap.getL2CacheHitRatio())
|
||||||
|
.addGauge(Interns.info(L2_CACHE_MISS_RATIO, L2_CACHE_MISS_RATIO_DESC),
|
||||||
|
rsWrap.getL2CacheMissRatio())
|
||||||
.addCounter(Interns.info(UPDATES_BLOCKED_TIME, UPDATES_BLOCKED_DESC),
|
.addCounter(Interns.info(UPDATES_BLOCKED_TIME, UPDATES_BLOCKED_DESC),
|
||||||
rsWrap.getUpdatesBlockedTime())
|
rsWrap.getUpdatesBlockedTime())
|
||||||
.addCounter(Interns.info(FLUSHED_CELLS, FLUSHED_CELLS_DESC),
|
.addCounter(Interns.info(FLUSHED_CELLS, FLUSHED_CELLS_DESC),
|
||||||
|
|
|
@ -525,6 +525,8 @@ public class CacheConfig {
|
||||||
// Clear this if in tests you'd make more than one block cache instance.
|
// Clear this if in tests you'd make more than one block cache instance.
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static BlockCache GLOBAL_BLOCK_CACHE_INSTANCE;
|
static BlockCache GLOBAL_BLOCK_CACHE_INSTANCE;
|
||||||
|
private static LruBlockCache GLOBAL_L1_CACHE_INSTANCE = null;
|
||||||
|
private static BlockCache GLOBAL_L2_CACHE_INSTANCE = null;
|
||||||
|
|
||||||
/** Boolean whether we have disabled the block cache entirely. */
|
/** Boolean whether we have disabled the block cache entirely. */
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
|
@ -535,6 +537,7 @@ public class CacheConfig {
|
||||||
* @return An L1 instance. Currently an instance of LruBlockCache.
|
* @return An L1 instance. Currently an instance of LruBlockCache.
|
||||||
*/
|
*/
|
||||||
private static LruBlockCache getL1(final Configuration c) {
|
private static LruBlockCache getL1(final Configuration c) {
|
||||||
|
if (GLOBAL_L1_CACHE_INSTANCE != null) return GLOBAL_L1_CACHE_INSTANCE;
|
||||||
final long lruCacheSize = HeapMemorySizeUtil.getLruCacheSize(c);
|
final long lruCacheSize = HeapMemorySizeUtil.getLruCacheSize(c);
|
||||||
if (lruCacheSize < 0) {
|
if (lruCacheSize < 0) {
|
||||||
blockCacheDisabled = true;
|
blockCacheDisabled = true;
|
||||||
|
@ -543,7 +546,8 @@ public class CacheConfig {
|
||||||
int blockSize = c.getInt(BLOCKCACHE_BLOCKSIZE_KEY, HConstants.DEFAULT_BLOCKSIZE);
|
int blockSize = c.getInt(BLOCKCACHE_BLOCKSIZE_KEY, HConstants.DEFAULT_BLOCKSIZE);
|
||||||
LOG.info("Allocating LruBlockCache size=" +
|
LOG.info("Allocating LruBlockCache size=" +
|
||||||
StringUtils.byteDesc(lruCacheSize) + ", blockSize=" + StringUtils.byteDesc(blockSize));
|
StringUtils.byteDesc(lruCacheSize) + ", blockSize=" + StringUtils.byteDesc(blockSize));
|
||||||
return new LruBlockCache(lruCacheSize, blockSize, true, c);
|
GLOBAL_L1_CACHE_INSTANCE = new LruBlockCache(lruCacheSize, blockSize, true, c);
|
||||||
|
return GLOBAL_L1_CACHE_INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -560,10 +564,26 @@ public class CacheConfig {
|
||||||
|
|
||||||
// If we want to use an external block cache then create that.
|
// If we want to use an external block cache then create that.
|
||||||
if (useExternal) {
|
if (useExternal) {
|
||||||
return getExternalBlockcache(c);
|
GLOBAL_L2_CACHE_INSTANCE = getExternalBlockcache(c);
|
||||||
}
|
} else {
|
||||||
// otherwise use the bucket cache.
|
// otherwise use the bucket cache.
|
||||||
return getBucketCache(c);
|
GLOBAL_L2_CACHE_INSTANCE = getBucketCache(c);
|
||||||
|
}
|
||||||
|
return GLOBAL_L2_CACHE_INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CacheStats getL1Stats() {
|
||||||
|
if (GLOBAL_L1_CACHE_INSTANCE != null) {
|
||||||
|
return GLOBAL_L1_CACHE_INSTANCE.getStats();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CacheStats getL2Stats() {
|
||||||
|
if (GLOBAL_L2_CACHE_INSTANCE != null) {
|
||||||
|
return GLOBAL_L2_CACHE_INSTANCE.getStats();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static BlockCache getExternalBlockcache(Configuration c) {
|
private static BlockCache getExternalBlockcache(Configuration c) {
|
||||||
|
|
|
@ -84,6 +84,8 @@ class MetricsRegionServerWrapperImpl
|
||||||
private volatile long averageRegionSize = 0L;
|
private volatile long averageRegionSize = 0L;
|
||||||
|
|
||||||
private CacheStats cacheStats;
|
private CacheStats cacheStats;
|
||||||
|
private CacheStats l1Stats = null;
|
||||||
|
private CacheStats l2Stats = null;
|
||||||
private ScheduledExecutorService executor;
|
private ScheduledExecutorService executor;
|
||||||
private Runnable runnable;
|
private Runnable runnable;
|
||||||
private long period;
|
private long period;
|
||||||
|
@ -113,9 +115,13 @@ class MetricsRegionServerWrapperImpl
|
||||||
*/
|
*/
|
||||||
private synchronized void initBlockCache() {
|
private synchronized void initBlockCache() {
|
||||||
CacheConfig cacheConfig = this.regionServer.cacheConfig;
|
CacheConfig cacheConfig = this.regionServer.cacheConfig;
|
||||||
if (cacheConfig != null && this.blockCache == null) {
|
if (cacheConfig != null) {
|
||||||
|
l1Stats = cacheConfig.getL1Stats();
|
||||||
|
l2Stats = cacheConfig.getL2Stats();
|
||||||
|
if (this.blockCache == null) {
|
||||||
this.blockCache = cacheConfig.getBlockCache();
|
this.blockCache = cacheConfig.getBlockCache();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (this.blockCache != null && this.cacheStats == null) {
|
if (this.blockCache != null && this.cacheStats == null) {
|
||||||
this.cacheStats = blockCache.getStats();
|
this.cacheStats = blockCache.getStats();
|
||||||
|
@ -328,6 +334,67 @@ class MetricsRegionServerWrapperImpl
|
||||||
return this.cacheStats.getFailedInserts();
|
return this.cacheStats.getFailedInserts();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getL1CacheHitCount() {
|
||||||
|
return 200;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getL1CacheMissCount() {
|
||||||
|
if (this.l1Stats == null) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return this.l1Stats.getMissCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getL1CacheHitRatio() {
|
||||||
|
if (this.l1Stats == null) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return this.l1Stats.getHitRatio();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getL1CacheMissRatio() {
|
||||||
|
if (this.l1Stats == null) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return this.l1Stats.getMissRatio();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getL2CacheHitCount() {
|
||||||
|
if (this.l2Stats == null) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return this.l2Stats.getHitCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getL2CacheMissCount() {
|
||||||
|
if (this.l2Stats == null) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return this.l2Stats.getMissCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getL2CacheHitRatio() {
|
||||||
|
if (this.l2Stats == null) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return this.l2Stats.getHitRatio();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getL2CacheMissRatio() {
|
||||||
|
if (this.l2Stats == null) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return this.l2Stats.getMissRatio();
|
||||||
|
}
|
||||||
|
|
||||||
@Override public void forceRecompute() {
|
@Override public void forceRecompute() {
|
||||||
this.runnable.run();
|
this.runnable.run();
|
||||||
}
|
}
|
||||||
|
|
|
@ -260,6 +260,46 @@ public class MetricsRegionServerWrapperStub implements MetricsRegionServerWrappe
|
||||||
return 36;
|
return 36;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getL1CacheHitCount() {
|
||||||
|
return 200;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getL1CacheMissCount() {
|
||||||
|
return 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getL1CacheHitRatio() {
|
||||||
|
return 80;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getL1CacheMissRatio() {
|
||||||
|
return 20;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getL2CacheHitCount() {
|
||||||
|
return 800;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getL2CacheMissCount() {
|
||||||
|
return 200;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getL2CacheHitRatio() {
|
||||||
|
return 90;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getL2CacheMissRatio() {
|
||||||
|
return 10;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getUpdatesBlockedTime() {
|
public long getUpdatesBlockedTime() {
|
||||||
return 419;
|
return 419;
|
||||||
|
|
|
@ -97,6 +97,14 @@ public class TestMetricsRegionServer {
|
||||||
HELPER.assertGauge("blockCacheCountHitPercent", 98, serverSource);
|
HELPER.assertGauge("blockCacheCountHitPercent", 98, serverSource);
|
||||||
HELPER.assertGauge("blockCacheExpressHitPercent", 97, serverSource);
|
HELPER.assertGauge("blockCacheExpressHitPercent", 97, serverSource);
|
||||||
HELPER.assertCounter("blockCacheFailedInsertionCount", 36, serverSource);
|
HELPER.assertCounter("blockCacheFailedInsertionCount", 36, serverSource);
|
||||||
|
HELPER.assertGauge("l1CacheHitCount", 200, serverSource);
|
||||||
|
HELPER.assertGauge("l1CacheMissCount", 100, serverSource);
|
||||||
|
HELPER.assertGauge("l1CacheHitRatio", 80, serverSource);
|
||||||
|
HELPER.assertGauge("l1CacheMissRatio", 20, serverSource);
|
||||||
|
HELPER.assertGauge("l2CacheHitCount", 800, serverSource);
|
||||||
|
HELPER.assertGauge("l2CacheMissCount", 200, serverSource);
|
||||||
|
HELPER.assertGauge("l2CacheHitRatio", 90, serverSource);
|
||||||
|
HELPER.assertGauge("l2CacheMissRatio", 10, serverSource);
|
||||||
HELPER.assertCounter("updatesBlockedTime", 419, serverSource);
|
HELPER.assertCounter("updatesBlockedTime", 419, serverSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue