mirror of https://github.com/apache/lucene.git
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:
parent
f49abe537a
commit
470dbb3858
|
@ -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
|
||||||
|
|
|
@ -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();
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -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();
|
||||||
}
|
}
|
||||||
|
|
|
@ -199,6 +199,7 @@ public class FreeTextSuggester extends Lookup {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 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;
|
||||||
|
|
|
@ -288,4 +288,9 @@ public class FSTCompletionLookup extends Lookup {
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long sizeInBytes() {
|
||||||
|
return RamUsageEstimator.sizeOf(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -220,4 +221,10 @@ public class TSTLookup extends Lookup {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Returns byte size of the underlying TST */
|
||||||
|
@Override
|
||||||
|
public long sizeInBytes() {
|
||||||
|
return RamUsageEstimator.sizeOf(autocomplete);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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(),
|
||||||
|
|
Loading…
Reference in New Issue