LUCENE-5323: add Lookup.sizeInBytes

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1538578 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2013-11-04 12:31:33 +00:00
parent f49abe537a
commit 470dbb3858
10 changed files with 43 additions and 10 deletions

View File

@ -139,6 +139,9 @@ New Features
a ValueSource, such as a NumericDocValuesField or an expression.
(Shai Erera)
* LUCENE-5323: Add .sizeInBytes method to all suggesters (Lookup).
(Areek Zillur via Mike McCandless)
Bug Fixes
* LUCENE-4998: Fixed a few places to pass IOContext.READONCE instead

View File

@ -201,4 +201,9 @@ public abstract class Lookup {
*/
public abstract boolean load(InputStream input) throws IOException;
/**
* Get the size of the underlying lookup implementation in memory
* @return ram size of the lookup implementation in bytes
*/
public abstract long sizeInBytes();
}

View File

@ -72,6 +72,7 @@ import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.IOUtils;
import org.apache.lucene.util.RamUsageEstimator;
import org.apache.lucene.util.Version;
// TODO:
@ -599,4 +600,9 @@ public class AnalyzingInfixSuggester extends Lookup implements Closeable {
dir = null;
}
}
@Override
public long sizeInBytes() {
return RamUsageEstimator.sizeOf(this);
}
};

View File

@ -250,6 +250,7 @@ public class AnalyzingSuggester extends Lookup {
}
/** Returns byte size of the underlying FST. */
@Override
public long sizeInBytes() {
return fst == null ? 0 : fst.sizeInBytes();
}

View File

@ -199,6 +199,7 @@ public class FreeTextSuggester extends Lookup {
}
/** Returns byte size of the underlying FST. */
@Override
public long sizeInBytes() {
if (fst == null) {
return 0;

View File

@ -288,4 +288,9 @@ public class FSTCompletionLookup extends Lookup {
}
return true;
}
@Override
public long sizeInBytes() {
return RamUsageEstimator.sizeOf(this);
}
}

View File

@ -287,4 +287,10 @@ public class WFSTCompletionLookup extends Lookup {
return left.compareTo(right);
}
};
/** Returns byte size of the underlying FST. */
@Override
public long sizeInBytes() {
return (fst == null) ? 0 : fst.sizeInBytes();
}
}

View File

@ -31,6 +31,7 @@ import org.apache.lucene.search.suggest.jaspell.JaspellTernarySearchTrie.TSTNode
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.CharsRef;
import org.apache.lucene.util.IOUtils;
import org.apache.lucene.util.RamUsageEstimator;
import org.apache.lucene.util.UnicodeUtil;
/**
@ -200,4 +201,10 @@ public class JaspellLookup extends Lookup {
}
return true;
}
/** Returns byte size of the underlying TST. */
@Override
public long sizeInBytes() {
return RamUsageEstimator.sizeOf(trie);
}
}

View File

@ -31,6 +31,7 @@ import org.apache.lucene.search.suggest.SortedInputIterator;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.CharsRef;
import org.apache.lucene.util.IOUtils;
import org.apache.lucene.util.RamUsageEstimator;
import org.apache.lucene.util.UnicodeUtil;
/**
@ -220,4 +221,10 @@ public class TSTLookup extends Lookup {
return true;
}
/** Returns byte size of the underlying TST */
@Override
public long sizeInBytes() {
return RamUsageEstimator.sizeOf(autocomplete);
}
}

View File

@ -144,15 +144,7 @@ public class LookupBenchmarkTest extends LuceneTestCase {
System.err.println("-- RAM consumption");
for (Class<? extends Lookup> cls : benchmarkClasses) {
Lookup lookup = buildLookup(cls, dictionaryInput);
long sizeInBytes;
if (lookup instanceof AnalyzingSuggester) {
// Just get size of FST: else we are also measuring
// size of MockAnalyzer which is non-trivial and
// varies depending on test seed:
sizeInBytes = ((AnalyzingSuggester) lookup).sizeInBytes();
} else {
sizeInBytes = RamUsageEstimator.sizeOf(lookup);
}
long sizeInBytes = lookup.sizeInBytes();
System.err.println(
String.format(Locale.ROOT, "%-15s size[B]:%,13d",
lookup.getClass().getSimpleName(),