mirror of https://github.com/apache/lucene.git
LUCENE-3886: Use RAMUsageEstimator for memory estimations in MemoryIndex. Because of more precise calculations, results may differ
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1302709 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a1538c6853
commit
c73356fb6c
|
@ -129,6 +129,10 @@ Changes in Runtime Behavior
|
|||
|
||||
* LUCENE-3698: FastVectorHighlighter no longer adds a multi value separator
|
||||
to the end of the highlighted text. (Shay Banon via Koji Sekiguchi)
|
||||
|
||||
* LUCENE-3867, LUCENE-3886: Use RAMUsageEstimator for memory estimations
|
||||
in MemoryIndex. Because of more precise calculations, results may differ.
|
||||
(Uwe Schindler)
|
||||
|
||||
New Features
|
||||
|
||||
|
|
|
@ -514,7 +514,6 @@ public class MemoryIndex {
|
|||
public String toString() {
|
||||
StringBuilder result = new StringBuilder(256);
|
||||
sortFields();
|
||||
int sumBytes = 0;
|
||||
int sumPositions = 0;
|
||||
int sumTerms = 0;
|
||||
|
||||
|
@ -525,7 +524,6 @@ public class MemoryIndex {
|
|||
info.sortTerms();
|
||||
result.append(fieldName + ":\n");
|
||||
|
||||
int numBytes = 0;
|
||||
int numPositions = 0;
|
||||
for (int j=0; j < info.sortedTerms.length; j++) {
|
||||
Map.Entry<BytesRef,ArrayIntList> e = info.sortedTerms[j];
|
||||
|
@ -535,22 +533,20 @@ public class MemoryIndex {
|
|||
result.append(positions.toString(stride)); // ignore offsets
|
||||
result.append("\n");
|
||||
numPositions += numPositions(positions);
|
||||
numBytes += term.length;
|
||||
}
|
||||
|
||||
result.append("\tterms=" + info.sortedTerms.length);
|
||||
result.append(", positions=" + numPositions);
|
||||
result.append(", Kbytes=" + (numBytes/1000.0f));
|
||||
result.append(", memory=" + RamUsageEstimator.humanReadableUnits(RamUsageEstimator.sizeOf(info)));
|
||||
result.append("\n");
|
||||
sumPositions += numPositions;
|
||||
sumBytes += numBytes;
|
||||
sumTerms += info.sortedTerms.length;
|
||||
}
|
||||
|
||||
result.append("\nfields=" + sortedFields.length);
|
||||
result.append(", terms=" + sumTerms);
|
||||
result.append(", positions=" + sumPositions);
|
||||
result.append(", Kbytes=" + (sumBytes/1000.0f));
|
||||
result.append(", memory=" + RamUsageEstimator.humanReadableUnits(getMemorySize()));
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
|
|
|
@ -52,7 +52,9 @@ import org.apache.lucene.search.spans.SpanMultiTermQueryWrapper;
|
|||
import org.apache.lucene.search.spans.SpanOrQuery;
|
||||
import org.apache.lucene.search.spans.SpanQuery;
|
||||
import org.apache.lucene.store.Directory;
|
||||
import org.apache.lucene.store.RAMDirectory;
|
||||
import org.apache.lucene.util.BytesRef;
|
||||
import org.apache.lucene.util.RamUsageEstimator;
|
||||
import org.apache.lucene.util._TestUtil;
|
||||
|
||||
/**
|
||||
|
@ -119,7 +121,7 @@ public class MemoryIndexTest extends BaseTokenStreamTestCase {
|
|||
termField.append(randomTerm());
|
||||
}
|
||||
|
||||
Directory ramdir = newDirectory();
|
||||
Directory ramdir = new RAMDirectory();
|
||||
Analyzer analyzer = randomAnalyzer();
|
||||
IndexWriter writer = new IndexWriter(ramdir,
|
||||
new IndexWriterConfig(TEST_VERSION_CURRENT, analyzer).setCodec(_TestUtil.alwaysPostingsFormat(new Lucene40PostingsFormat())));
|
||||
|
@ -134,8 +136,18 @@ public class MemoryIndexTest extends BaseTokenStreamTestCase {
|
|||
MemoryIndex memory = new MemoryIndex();
|
||||
memory.addField("foo", fooField.toString(), analyzer);
|
||||
memory.addField("term", termField.toString(), analyzer);
|
||||
|
||||
if (VERBOSE) {
|
||||
System.out.println("Random MemoryIndex:\n" + memory.toString());
|
||||
System.out.println("Same index as RAMDirectory: " +
|
||||
RamUsageEstimator.humanReadableUnits(RamUsageEstimator.sizeOf(ramdir)));
|
||||
System.out.println();
|
||||
} else {
|
||||
assertTrue(memory.getMemorySize() > 0L);
|
||||
}
|
||||
|
||||
assertAllQueries(memory, ramdir, analyzer);
|
||||
ramdir.close();
|
||||
ramdir.close();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue