HBASE-11320 Reenable bucket cache logging
This commit is contained in:
parent
4d200be620
commit
2ab3b325ca
|
@ -229,7 +229,7 @@ public class BlockCacheUtil {
|
||||||
/**
|
/**
|
||||||
* Use one of these to keep a running account of cached blocks by file. Throw it away when done.
|
* Use one of these to keep a running account of cached blocks by file. Throw it away when done.
|
||||||
* This is different than metrics in that it is stats on current state of a cache.
|
* This is different than metrics in that it is stats on current state of a cache.
|
||||||
* @see getLoadedCachedBlocksByFile
|
* See getLoadedCachedBlocksByFile
|
||||||
*/
|
*/
|
||||||
@JsonIgnoreProperties({"cachedBlockStatsByFile"})
|
@JsonIgnoreProperties({"cachedBlockStatsByFile"})
|
||||||
public static class CachedBlocksByFile {
|
public static class CachedBlocksByFile {
|
||||||
|
|
|
@ -140,12 +140,8 @@ public class LruBlockCache implements ResizableBlockCache, HeapSize {
|
||||||
private final EvictionThread evictionThread;
|
private final EvictionThread evictionThread;
|
||||||
|
|
||||||
/** Statistics thread schedule pool (for heavy debugging, could remove) */
|
/** Statistics thread schedule pool (for heavy debugging, could remove) */
|
||||||
private final ScheduledExecutorService scheduleThreadPool =
|
private final ScheduledExecutorService scheduleThreadPool = Executors.newScheduledThreadPool(1,
|
||||||
Executors.newScheduledThreadPool(1,
|
new ThreadFactoryBuilder().setNameFormat("LruBlockCacheStatsExecutor").setDaemon(true).build());
|
||||||
new ThreadFactoryBuilder()
|
|
||||||
.setNameFormat("LruStats #%d")
|
|
||||||
.setDaemon(true)
|
|
||||||
.build());
|
|
||||||
|
|
||||||
/** Current size of cache */
|
/** Current size of cache */
|
||||||
private final AtomicLong size;
|
private final AtomicLong size;
|
||||||
|
@ -286,6 +282,8 @@ public class LruBlockCache implements ResizableBlockCache, HeapSize {
|
||||||
} else {
|
} else {
|
||||||
this.evictionThread = null;
|
this.evictionThread = null;
|
||||||
}
|
}
|
||||||
|
// TODO: Add means of turning this off. Bit obnoxious running thread just to make a log
|
||||||
|
// every five minutes.
|
||||||
this.scheduleThreadPool.scheduleAtFixedRate(new StatisticsThread(this),
|
this.scheduleThreadPool.scheduleAtFixedRate(new StatisticsThread(this),
|
||||||
statThreadPeriod, statThreadPeriod, TimeUnit.SECONDS);
|
statThreadPeriod, statThreadPeriod, TimeUnit.SECONDS);
|
||||||
}
|
}
|
||||||
|
@ -732,13 +730,14 @@ public class LruBlockCache implements ResizableBlockCache, HeapSize {
|
||||||
* Statistics thread. Periodically prints the cache statistics to the log.
|
* Statistics thread. Periodically prints the cache statistics to the log.
|
||||||
*/
|
*/
|
||||||
static class StatisticsThread extends Thread {
|
static class StatisticsThread extends Thread {
|
||||||
LruBlockCache lru;
|
private final LruBlockCache lru;
|
||||||
|
|
||||||
public StatisticsThread(LruBlockCache lru) {
|
public StatisticsThread(LruBlockCache lru) {
|
||||||
super("LruBlockCache.StatisticsThread");
|
super("LruBlockCacheStats");
|
||||||
setDaemon(true);
|
setDaemon(true);
|
||||||
this.lru = lru;
|
this.lru = lru;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
lru.logStats();
|
lru.logStats();
|
||||||
|
@ -746,22 +745,20 @@ public class LruBlockCache implements ResizableBlockCache, HeapSize {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void logStats() {
|
public void logStats() {
|
||||||
if (!LOG.isDebugEnabled()) return;
|
|
||||||
// Log size
|
// Log size
|
||||||
long totalSize = heapSize();
|
long totalSize = heapSize();
|
||||||
long freeSize = maxSize - totalSize;
|
long freeSize = maxSize - totalSize;
|
||||||
LruBlockCache.LOG.debug("Total=" + StringUtils.byteDesc(totalSize) + ", " +
|
LruBlockCache.LOG.info("totalSize=" + StringUtils.byteDesc(totalSize) + ", " +
|
||||||
"free=" + StringUtils.byteDesc(freeSize) + ", " +
|
"freeSize=" + StringUtils.byteDesc(freeSize) + ", " +
|
||||||
"max=" + StringUtils.byteDesc(this.maxSize) + ", " +
|
"max=" + StringUtils.byteDesc(this.maxSize) + ", " +
|
||||||
"blocks=" + size() +", " +
|
|
||||||
"accesses=" + stats.getRequestCount() + ", " +
|
"accesses=" + stats.getRequestCount() + ", " +
|
||||||
"hits=" + stats.getHitCount() + ", " +
|
"hits=" + stats.getHitCount() + ", " +
|
||||||
"hitRatio=" +
|
"hitRatio=" + (stats.getHitCount() == 0 ?
|
||||||
(stats.getHitCount() == 0 ? "0" : (StringUtils.formatPercent(stats.getHitRatio(), 2)+ ", ")) + ", " +
|
"0" : (StringUtils.formatPercent(stats.getHitRatio(), 2)+ ", ")) + ", " +
|
||||||
"cachingAccesses=" + stats.getRequestCachingCount() + ", " +
|
"cachingAccesses=" + stats.getRequestCachingCount() + ", " +
|
||||||
"cachingHits=" + stats.getHitCachingCount() + ", " +
|
"cachingHits=" + stats.getHitCachingCount() + ", " +
|
||||||
"cachingHitsRatio=" +
|
"cachingHitsRatio=" + (stats.getHitCachingCount() == 0 ?
|
||||||
(stats.getHitCachingCount() == 0 ? "0,": (StringUtils.formatPercent(stats.getHitCachingRatio(), 2) + ", ")) +
|
"0,": (StringUtils.formatPercent(stats.getHitCachingRatio(), 2) + ", ")) +
|
||||||
"evictions=" + stats.getEvictionCount() + ", " +
|
"evictions=" + stats.getEvictionCount() + ", " +
|
||||||
"evicted=" + stats.getEvictedCount() + ", " +
|
"evicted=" + stats.getEvictedCount() + ", " +
|
||||||
"evictedPerRun=" + stats.evictedPerEviction());
|
"evictedPerRun=" + stats.evictedPerEviction());
|
||||||
|
@ -782,7 +779,7 @@ public class LruBlockCache implements ResizableBlockCache, HeapSize {
|
||||||
(5 * Bytes.SIZEOF_FLOAT) + Bytes.SIZEOF_BOOLEAN
|
(5 * Bytes.SIZEOF_FLOAT) + Bytes.SIZEOF_BOOLEAN
|
||||||
+ ClassSize.OBJECT);
|
+ ClassSize.OBJECT);
|
||||||
|
|
||||||
// HeapSize implementation
|
@Override
|
||||||
public long heapSize() {
|
public long heapSize() {
|
||||||
return getCurrentSize();
|
return getCurrentSize();
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
|
||||||
import com.google.common.base.Objects;
|
import com.google.common.base.Objects;
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.apache.hadoop.classification.InterfaceAudience;
|
import org.apache.hadoop.classification.InterfaceAudience;
|
||||||
|
@ -512,21 +513,7 @@ public final class BucketAllocator {
|
||||||
return this.buckets;
|
return this.buckets;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dumpToLog() {
|
void logStatistics() {
|
||||||
logStatistics();
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
for (Bucket b : buckets) {
|
|
||||||
sb.append("Bucket:").append(b.baseOffset).append('\n');
|
|
||||||
sb.append(" Size index: " + b.sizeIndex() + "; Free:" + b.freeCount
|
|
||||||
+ "; used:" + b.usedCount + "; freelist\n");
|
|
||||||
for (int i = 0; i < b.freeCount(); ++i)
|
|
||||||
sb.append(b.freeList[i]).append(',');
|
|
||||||
sb.append('\n');
|
|
||||||
}
|
|
||||||
LOG.info(sb);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void logStatistics() {
|
|
||||||
IndexStatistics total = new IndexStatistics();
|
IndexStatistics total = new IndexStatistics();
|
||||||
IndexStatistics[] stats = getIndexStatistics(total);
|
IndexStatistics[] stats = getIndexStatistics(total);
|
||||||
LOG.info("Bucket allocator statistics follow:\n");
|
LOG.info("Bucket allocator statistics follow:\n");
|
||||||
|
@ -538,7 +525,7 @@ public final class BucketAllocator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IndexStatistics[] getIndexStatistics(IndexStatistics grandTotal) {
|
IndexStatistics[] getIndexStatistics(IndexStatistics grandTotal) {
|
||||||
IndexStatistics[] stats = getIndexStatistics();
|
IndexStatistics[] stats = getIndexStatistics();
|
||||||
long totalfree = 0, totalused = 0;
|
long totalfree = 0, totalused = 0;
|
||||||
for (IndexStatistics stat : stats) {
|
for (IndexStatistics stat : stats) {
|
||||||
|
@ -549,7 +536,7 @@ public final class BucketAllocator {
|
||||||
return stats;
|
return stats;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IndexStatistics[] getIndexStatistics() {
|
IndexStatistics[] getIndexStatistics() {
|
||||||
IndexStatistics[] stats = new IndexStatistics[bucketSizes.length];
|
IndexStatistics[] stats = new IndexStatistics[bucketSizes.length];
|
||||||
for (int i = 0; i < stats.length; ++i)
|
for (int i = 0; i < stats.length; ++i)
|
||||||
stats[i] = bucketSizeInfos[i].statistics();
|
stats[i] = bucketSizeInfos[i].statistics();
|
||||||
|
|
|
@ -103,7 +103,7 @@ public class BucketCache implements BlockCache, HeapSize {
|
||||||
private static final float DEFAULT_MIN_FACTOR = 0.85f;
|
private static final float DEFAULT_MIN_FACTOR = 0.85f;
|
||||||
|
|
||||||
/** Statistics thread */
|
/** Statistics thread */
|
||||||
private static final int statThreadPeriod = 3 * 60;
|
private static final int statThreadPeriod = 5 * 60;
|
||||||
|
|
||||||
final static int DEFAULT_WRITER_THREADS = 3;
|
final static int DEFAULT_WRITER_THREADS = 3;
|
||||||
final static int DEFAULT_WRITER_QUEUE_ITEMS = 64;
|
final static int DEFAULT_WRITER_QUEUE_ITEMS = 64;
|
||||||
|
@ -188,12 +188,8 @@ public class BucketCache implements BlockCache, HeapSize {
|
||||||
});
|
});
|
||||||
|
|
||||||
/** Statistics thread schedule pool (for heavy debugging, could remove) */
|
/** Statistics thread schedule pool (for heavy debugging, could remove) */
|
||||||
private final ScheduledExecutorService scheduleThreadPool =
|
private final ScheduledExecutorService scheduleThreadPool = Executors.newScheduledThreadPool(1,
|
||||||
Executors.newScheduledThreadPool(1,
|
new ThreadFactoryBuilder().setNameFormat("BucketCacheStatsExecutor").setDaemon(true).build());
|
||||||
new ThreadFactoryBuilder()
|
|
||||||
.setNameFormat("BucketCache Statistics #%d")
|
|
||||||
.setDaemon(true)
|
|
||||||
.build());
|
|
||||||
|
|
||||||
// Allocate or free space for the block
|
// Allocate or free space for the block
|
||||||
private BucketAllocator bucketAllocator;
|
private BucketAllocator bucketAllocator;
|
||||||
|
@ -252,6 +248,8 @@ public class BucketCache implements BlockCache, HeapSize {
|
||||||
writerThreads[i].start();
|
writerThreads[i].start();
|
||||||
}
|
}
|
||||||
// Run the statistics thread periodically to print the cache statistics log
|
// Run the statistics thread periodically to print the cache statistics log
|
||||||
|
// TODO: Add means of turning this off. Bit obnoxious running thread just to make a log
|
||||||
|
// every five minutes.
|
||||||
this.scheduleThreadPool.scheduleAtFixedRate(new StatisticsThread(this),
|
this.scheduleThreadPool.scheduleAtFixedRate(new StatisticsThread(this),
|
||||||
statThreadPeriod, statThreadPeriod, TimeUnit.SECONDS);
|
statThreadPeriod, statThreadPeriod, TimeUnit.SECONDS);
|
||||||
LOG.info("Started bucket cache; ioengine=" + ioEngineName +
|
LOG.info("Started bucket cache; ioengine=" + ioEngineName +
|
||||||
|
@ -445,16 +443,15 @@ public class BucketCache implements BlockCache, HeapSize {
|
||||||
/*
|
/*
|
||||||
* Statistics thread. Periodically output cache statistics to the log.
|
* Statistics thread. Periodically output cache statistics to the log.
|
||||||
*/
|
*/
|
||||||
// TODO: Fix. We run a thread to log at DEBUG. If no DEBUG level, we still run the thread!
|
|
||||||
// A thread just to log is OTT. FIX.
|
|
||||||
private static class StatisticsThread extends Thread {
|
private static class StatisticsThread extends Thread {
|
||||||
BucketCache bucketCache;
|
private final BucketCache bucketCache;
|
||||||
|
|
||||||
public StatisticsThread(BucketCache bucketCache) {
|
public StatisticsThread(BucketCache bucketCache) {
|
||||||
super("BucketCache.StatisticsThread");
|
super("BucketCacheStatsThread");
|
||||||
setDaemon(true);
|
setDaemon(true);
|
||||||
this.bucketCache = bucketCache;
|
this.bucketCache = bucketCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
bucketCache.logStats();
|
bucketCache.logStats();
|
||||||
|
@ -462,16 +459,13 @@ public class BucketCache implements BlockCache, HeapSize {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void logStats() {
|
public void logStats() {
|
||||||
if (!LOG.isDebugEnabled()) return;
|
|
||||||
// Log size
|
|
||||||
long totalSize = bucketAllocator.getTotalSize();
|
long totalSize = bucketAllocator.getTotalSize();
|
||||||
long usedSize = bucketAllocator.getUsedSize();
|
long usedSize = bucketAllocator.getUsedSize();
|
||||||
long freeSize = totalSize - usedSize;
|
long freeSize = totalSize - usedSize;
|
||||||
long cacheSize = this.realCacheSize.get();
|
long cacheSize = getRealCacheSize();
|
||||||
LOG.debug("BucketCache Stats: " +
|
LOG.info("failedBlockAdditions=" + getFailedBlockAdditions() + ", " +
|
||||||
"failedBlockAdditions=" + this.failedBlockAdditions.get() + ", " +
|
"totalSize=" + StringUtils.byteDesc(totalSize) + ", " +
|
||||||
"total=" + StringUtils.byteDesc(totalSize) + ", " +
|
"freeSize=" + StringUtils.byteDesc(freeSize) + ", " +
|
||||||
"free=" + StringUtils.byteDesc(freeSize) + ", " +
|
|
||||||
"usedSize=" + StringUtils.byteDesc(usedSize) +", " +
|
"usedSize=" + StringUtils.byteDesc(usedSize) +", " +
|
||||||
"cacheSize=" + StringUtils.byteDesc(cacheSize) +", " +
|
"cacheSize=" + StringUtils.byteDesc(cacheSize) +", " +
|
||||||
"accesses=" + cacheStats.getRequestCount() + ", " +
|
"accesses=" + cacheStats.getRequestCount() + ", " +
|
||||||
|
@ -490,6 +484,14 @@ public class BucketCache implements BlockCache, HeapSize {
|
||||||
cacheStats.reset();
|
cacheStats.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long getFailedBlockAdditions() {
|
||||||
|
return this.failedBlockAdditions.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getRealCacheSize() {
|
||||||
|
return this.realCacheSize.get();
|
||||||
|
}
|
||||||
|
|
||||||
private long acceptableSize() {
|
private long acceptableSize() {
|
||||||
return (long) Math.floor(bucketAllocator.getTotalSize() * DEFAULT_ACCEPT_FACTOR);
|
return (long) Math.floor(bucketAllocator.getTotalSize() * DEFAULT_ACCEPT_FACTOR);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6179,7 +6179,7 @@ public class HRegion implements HeapSize { // , Writable{
|
||||||
* @param wal
|
* @param wal
|
||||||
* @param cells list of KeyValues inserted into memstore. Those KeyValues are passed in order to
|
* @param cells list of KeyValues inserted into memstore. Those KeyValues are passed in order to
|
||||||
* be updated with right mvcc values(their log sequence nu
|
* be updated with right mvcc values(their log sequence nu
|
||||||
* @return
|
* @return Return the key used appending with no sync and no append.
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
private HLogKey appendNoSyncNoAppend(final HLog wal, List<KeyValue> cells) throws IOException {
|
private HLogKey appendNoSyncNoAppend(final HLog wal, List<KeyValue> cells) throws IOException {
|
||||||
|
|
|
@ -62,7 +62,7 @@ public class MultiVersionConsistencyControl {
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param initVal The value we used initially and expected it'll be reset later
|
* @param initVal The value we used initially and expected it'll be reset later
|
||||||
* @return
|
* @return WriteEntry instance.
|
||||||
*/
|
*/
|
||||||
WriteEntry beginMemstoreInsert() {
|
WriteEntry beginMemstoreInsert() {
|
||||||
return beginMemstoreInsertWithSeqNum(NO_WRITE_NUMBER);
|
return beginMemstoreInsertWithSeqNum(NO_WRITE_NUMBER);
|
||||||
|
|
Loading…
Reference in New Issue