From e40d280115ca315349ebf890a97881474d43656f Mon Sep 17 00:00:00 2001 From: "Hiram R. Chirino" Date: Thu, 16 May 2013 14:49:51 +0000 Subject: [PATCH] Reduce how often forced leveldb compactions occur. git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1483395 13f79535-47bb-0310-9956-ffa450edef68 --- .../activemq/leveldb/LevelDBClient.scala | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/activemq-leveldb-store/src/main/scala/org/apache/activemq/leveldb/LevelDBClient.scala b/activemq-leveldb-store/src/main/scala/org/apache/activemq/leveldb/LevelDBClient.scala index 81bfa45713..8adeb539c0 100755 --- a/activemq-leveldb-store/src/main/scala/org/apache/activemq/leveldb/LevelDBClient.scala +++ b/activemq-leveldb-store/src/main/scala/org/apache/activemq/leveldb/LevelDBClient.scala @@ -1408,27 +1408,32 @@ class LevelDBClient(store: LevelDBStore) { // How much space is the dirty index using?? var index_usage = 0L for( file <- dirtyIndexFile.recursiveList ) { - if(!file.isDirectory) { + if(!file.isDirectory && file.getName.endsWith(".sst") ) { index_usage += file.length() } } + // Lets use the log_refs to get a rough estimate on how many entries are store in leveldb. var index_queue_entries=0L for ( (_, count) <- logRefs ) { index_queue_entries += count.get() } - 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)) + // Don't force compactions until level 0 is full. + val SSL_FILE_SIZE = 1024*1024*4L + 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. - if( ratio > store.autoCompactionRatio ) { + // lets compact if we go way over the healthy ratio. + if( ratio > store.autoCompactionRatio ) { + index.compact_needed = true + } + } else { + // at most the index should have 1 full level file. 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 } }