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. a ValueSource, such as a NumericDocValuesField or an expression.
(Shai Erera) (Shai Erera)
* LUCENE-5323: Add .sizeInBytes method to all suggesters (Lookup).
(Areek Zillur via Mike McCandless)
Bug Fixes Bug Fixes
* LUCENE-4998: Fixed a few places to pass IOContext.READONCE instead * 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; 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.store.FSDirectory;
import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.IOUtils; import org.apache.lucene.util.IOUtils;
import org.apache.lucene.util.RamUsageEstimator;
import org.apache.lucene.util.Version; import org.apache.lucene.util.Version;
// TODO: // TODO:
@ -599,4 +600,9 @@ public class AnalyzingInfixSuggester extends Lookup implements Closeable {
dir = null; 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. */ /** Returns byte size of the underlying FST. */
@Override
public long sizeInBytes() { public long sizeInBytes() {
return fst == null ? 0 : fst.sizeInBytes(); return fst == null ? 0 : fst.sizeInBytes();
} }

View File

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

View File

@ -288,4 +288,9 @@ public class FSTCompletionLookup extends Lookup {
} }
return true; 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); 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.BytesRef;
import org.apache.lucene.util.CharsRef; import org.apache.lucene.util.CharsRef;
import org.apache.lucene.util.IOUtils; import org.apache.lucene.util.IOUtils;
import org.apache.lucene.util.RamUsageEstimator;
import org.apache.lucene.util.UnicodeUtil; import org.apache.lucene.util.UnicodeUtil;
/** /**
@ -200,4 +201,10 @@ public class JaspellLookup extends Lookup {
} }
return true; 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.BytesRef;
import org.apache.lucene.util.CharsRef; import org.apache.lucene.util.CharsRef;
import org.apache.lucene.util.IOUtils; import org.apache.lucene.util.IOUtils;
import org.apache.lucene.util.RamUsageEstimator;
import org.apache.lucene.util.UnicodeUtil; import org.apache.lucene.util.UnicodeUtil;
/** /**
@ -219,5 +220,11 @@ public class TSTLookup extends Lookup {
} }
return true; 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"); System.err.println("-- RAM consumption");
for (Class<? extends Lookup> cls : benchmarkClasses) { for (Class<? extends Lookup> cls : benchmarkClasses) {
Lookup lookup = buildLookup(cls, dictionaryInput); Lookup lookup = buildLookup(cls, dictionaryInput);
long sizeInBytes; long sizeInBytes = lookup.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);
}
System.err.println( System.err.println(
String.format(Locale.ROOT, "%-15s size[B]:%,13d", String.format(Locale.ROOT, "%-15s size[B]:%,13d",
lookup.getClass().getSimpleName(), lookup.getClass().getSimpleName(),