Reduce how often forced leveldb compactions occur.

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1483395 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Hiram R. Chirino 2013-05-16 14:49:51 +00:00
parent 086e9de9ac
commit e40d280115
1 changed files with 14 additions and 9 deletions

View File

@ -1408,27 +1408,32 @@ class LevelDBClient(store: LevelDBStore) {
// How much space is the dirty index using?? // How much space is the dirty index using??
var index_usage = 0L var index_usage = 0L
for( file <- dirtyIndexFile.recursiveList ) { for( file <- dirtyIndexFile.recursiveList ) {
if(!file.isDirectory) { if(!file.isDirectory && file.getName.endsWith(".sst") ) {
index_usage += file.length() index_usage += file.length()
} }
} }
// Lets use the log_refs to get a rough estimate on how many entries are store in leveldb. // Lets use the log_refs to get a rough estimate on how many entries are store in leveldb.
var index_queue_entries=0L var index_queue_entries=0L
for ( (_, count) <- logRefs ) { for ( (_, count) <- logRefs ) {
index_queue_entries += count.get() index_queue_entries += count.get()
} }
if ( index_queue_entries > 0 ) { // Don't force compactions until level 0 is full.
val ratio = (index_usage*1.0f/index_queue_entries) val SSL_FILE_SIZE = 1024*1024*4L
// println("usage: index_usage:%d, index_queue_entries:%d, ratio: %f".format(index_usage, index_queue_entries, ratio)) if( index_usage > SSL_FILE_SIZE*10 ) {
if ( index_queue_entries > 0 ) {
val ratio = (index_usage*1.0f/index_queue_entries)
// println("usage: index_usage:%d, index_queue_entries:%d, ratio: %f".format(index_usage, index_queue_entries, ratio))
// lets compact if we go way over the healthy ratio. // lets compact if we go way over the healthy ratio.
if( ratio > store.autoCompactionRatio ) { if( ratio > store.autoCompactionRatio ) {
index.compact_needed = true
}
} else {
// at most the index should have 1 full level file.
index.compact_needed = true index.compact_needed = true
} }
} else if( index_usage > 1024*1024*5 ) {
// at most the index should have 1 full level file.
index.compact_needed = true
} }
} }