LUCENE-1136: add ability to not count sub-task doLogic increment to contri/benchmark

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@614956 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Doron Cohen 2008-01-24 18:46:57 +00:00
parent 7f09c9f00e
commit 8ace4103a7
7 changed files with 121 additions and 12 deletions

View File

@ -4,6 +4,8 @@ The Benchmark contrib package contains code for benchmarking Lucene in a variety
$Id:$
1/24/2008
LUCENE-1136: add ability to not count sub-task doLogic increment
1/23/2008
LUCENE-1129: ReadTask properly uses the traversalSize value

View File

@ -50,10 +50,10 @@ log.queries=true
ResetSystemErase
{ "Populate"
CreateIndex
-CreateIndex
{ "MAddDocs" AddDoc > : 2000
Optimize
CloseIndex
-Optimize
-CloseIndex
}
OpenReader

View File

@ -290,6 +290,15 @@ The following is an informal description of the supported syntax.
waiting before starting next add, if otherwise rate would exceed 200 adds/min.
</li>
<li>
<b>Disable Counting</b>: Each task executed contributes to the records count.
This count is reflected in reports under recs/s and under recsPerRun.
Most tasks count 1, some count 0, and some count more.
(See <a href="#recsCounting">Results record counting clarified</a> for more details.)
It is possible to disable counting for a task by preceding it with <font color="#FF0066">-</font>.
<br>Example - <font color="#FF0066"> -CreateIndex </font> - would count 0 while
the default behavior for CreateIndex is to count 1.
</li>
<li>
<b>Command names</b>: Each class "AnyNameTask" in the
package org.apache.lucene.benchmark.byTask.tasks,
that extends PerfTask, is supported as command "AnyName" that can be

View File

@ -41,6 +41,7 @@ public abstract class PerfTask implements Cloneable {
private String name;
private int depth = 0;
private int maxDepthLogStart = 0;
private boolean disableCounting = false;
protected String params = null;
protected static final String NEW_LINE = System.getProperty("line.separator");
@ -81,6 +82,7 @@ public abstract class PerfTask implements Cloneable {
if (!reportStats || shouldNotRecordStats()) {
setup();
int count = doLogic();
count = disableCounting ? 0 : count;
tearDown();
return count;
}
@ -88,6 +90,7 @@ public abstract class PerfTask implements Cloneable {
Points pnts = runData.getPoints();
TaskStats ts = pnts.markTaskStart(this,runData.getConfig().getRoundNumber());
int count = doLogic();
count = disableCounting ? 0 : count;
pnts.markTaskEnd(ts, count);
tearDown();
return count;
@ -153,6 +156,9 @@ public abstract class PerfTask implements Cloneable {
public String toString() {
String padd = getPadding();
StringBuffer sb = new StringBuffer(padd);
if (disableCounting) {
sb.append('-');
}
sb.append(getName());
return sb.toString();
}
@ -227,4 +233,18 @@ public abstract class PerfTask implements Cloneable {
return params;
}
/**
* Return true if counting is disabled for this task.
*/
public boolean isDisableCounting() {
return disableCounting;
}
/**
* See {@link #isDisableCounting()}
*/
public void setDisableCounting(boolean disableCounting) {
this.disableCounting = disableCounting;
}
}

View File

@ -40,9 +40,11 @@ public class TaskSequence extends PerfTask {
private boolean resetExhausted = false;
private PerfTask[] tasksArray;
private boolean anyExhaustibleTasks;
private boolean collapsable = false; // to not collapse external sequence named in alg.
public TaskSequence (PerfRunData runData, String name, TaskSequence parent, boolean parallel) {
super(runData);
collapsable = (name == null);
name = (name!=null ? name : (parallel ? "Par" : "Seq"));
setName(name);
setSequenceName();
@ -339,4 +341,11 @@ public class TaskSequence extends PerfTask {
return res;
}
/**
* Return true if can be collapsed in case it is outermost sequence
*/
public boolean isCollapsable() {
return collapsable;
}
}

View File

@ -51,7 +51,9 @@ public class Algorithm {
stok.ordinaryChar('/');
stok.ordinaryChar('(');
stok.ordinaryChar(')');
stok.ordinaryChar('-');
boolean colonOk = false;
boolean isDisableCountNextTask = false; // only for primitive tasks
currSequence.setDepth(0);
String taskPackage = PerfTask.class.getPackage().getName() + ".";
@ -65,6 +67,8 @@ public class Algorithm {
String s = stok.sval;
Constructor cnstr = Class.forName(taskPackage+s+"Task").getConstructor(paramClass);
PerfTask task = (PerfTask) cnstr.newInstance(paramObj);
task.setDisableCounting(isDisableCountNextTask);
isDisableCountNextTask = false;
currSequence.addTask(task);
if (task instanceof RepSumByPrefTask) {
stok.nextToken();
@ -120,7 +124,8 @@ public class Algorithm {
if ((char)stok.ttype == '*') {
((TaskSequence)prevTask).setRepetitions(TaskSequence.REPEAT_EXHAUST);
} else {
if (stok.ttype!=StreamTokenizer.TT_NUMBER) throw new Exception("expected repetitions number: - "+stok.toString());
if (stok.ttype!=StreamTokenizer.TT_NUMBER)
throw new Exception("expected repetitions number: - "+stok.toString());
((TaskSequence)prevTask).setRepetitions((int)stok.nval);
}
// check for rate specification (ops/min)
@ -184,6 +189,10 @@ public class Algorithm {
currSequence = currSequence.getParent();
break;
case '-' :
isDisableCountNextTask = true;
break;
} //switch(c)
break;
@ -196,7 +205,7 @@ public class Algorithm {
}
// remove redundant top level enclosing sequences
while (sequence.getRepetitions()==1 && sequence.getRate()==0) {
while (sequence.isCollapsable() && sequence.getRepetitions()==1 && sequence.getRate()==0) {
ArrayList t = sequence.getTasks();
if (t!=null && t.size()==1) {
PerfTask p = (PerfTask) t.get(0);
@ -225,7 +234,7 @@ public class Algorithm {
* @throws Exception
*/
public void execute() throws Exception {
sequence.doLogic();
sequence.runAndMaybeStats(true);
}
/**

View File

@ -24,6 +24,7 @@ import java.io.BufferedReader;
import java.util.List;
import java.util.Iterator;
import org.apache.lucene.benchmark.byTask.Benchmark;
import org.apache.lucene.benchmark.byTask.feeds.DocData;
import org.apache.lucene.benchmark.byTask.feeds.NoMoreDataException;
import org.apache.lucene.benchmark.byTask.feeds.ReutersDocMaker;
@ -194,6 +195,7 @@ public class TestPerfTasksLogic extends TestCase {
try {
Benchmark benchmark = execBenchmark(algLines);
assertTrue("CountingHighlighterTest should have thrown an exception", false);
assertNotNull(benchmark); // (avoid compile warning on unused variable)
} catch (Exception e) {
assertTrue(true);
}
@ -311,7 +313,6 @@ public class TestPerfTasksLogic extends TestCase {
"doc.maker=org.apache.lucene.benchmark.byTask.feeds.LineDocMaker",
"docs.file=" + lineFile.getAbsolutePath().replace('\\', '/'),
"doc.maker.forever=false",
"doc.maker.forever=false",
"doc.reuse.fields=false",
"autocommit=false",
"ram.flush.mb=4",
@ -404,7 +405,7 @@ public class TestPerfTasksLogic extends TestCase {
"directory=RAMDirectory",
"doc.stored=false",
"doc.tokenized=false",
"debug.level=1",
"task.max.depth.log=1",
"# ----- alg ",
"CreateIndex",
"{ [ AddDoc]: 4} : * ",
@ -482,7 +483,7 @@ public class TestPerfTasksLogic extends TestCase {
"directory=RAMDirectory",
"doc.stored=false",
"doc.tokenized=false",
"debug.level=1",
"task.max.depth.log=1",
"# ----- alg ",
"{ \"Rounds\"",
" ResetSystemErase",
@ -658,7 +659,7 @@ public class TestPerfTasksLogic extends TestCase {
Benchmark benchmark = execBenchmark(algLines);
final IndexWriter writer = benchmark.getRunData().getIndexWriter();
assertEquals(2, writer.getMaxBufferedDocs());
assertEquals(writer.DISABLE_AUTO_FLUSH, (int) writer.getRAMBufferSizeMB());
assertEquals(IndexWriter.DISABLE_AUTO_FLUSH, (int) writer.getRAMBufferSizeMB());
assertEquals(3, writer.getMergeFactor());
assertEquals(false, writer.getUseCompoundFile());
}
@ -708,4 +709,63 @@ public class TestPerfTasksLogic extends TestCase {
cfsCount++;
assertEquals(3, cfsCount);
}
/**
* Test disabling task count (LUCENE-1136).
*/
public void testDisableCounting() throws Exception {
doTestDisableCounting(true);
doTestDisableCounting(false);
}
private void doTestDisableCounting(boolean disable) throws Exception {
// 1. alg definition (required in every "logic" test)
String algLines[] = disableCountingLines(disable);
// 2. execute the algorithm (required in every "logic" test)
Benchmark benchmark = execBenchmark(algLines);
// 3. test counters
int n = disable ? 0 : 1;
int nChecked = 0;
for (Iterator ts = benchmark.getRunData().getPoints().taskStats().iterator(); ts.hasNext();) {
TaskStats stats = (TaskStats) ts.next();
String taskName = stats.getTask().getName();
if (taskName.equals("Rounds")) {
assertEquals("Wrong total count!",20+2*n,stats.getCount());
nChecked++;
} else if (taskName.equals("CreateIndex")) {
assertEquals("Wrong count for CreateIndex!",n,stats.getCount());
nChecked++;
} else if (taskName.equals("CloseIndex")) {
assertEquals("Wrong count for CloseIndex!",n,stats.getCount());
nChecked++;
}
}
assertEquals("Missing some tasks to check!",3,nChecked);
}
private static String[] disableCountingLines (boolean disable) {
String dis = disable ? "-" : "";
return new String[] {
"# ----- properties ",
"doc.maker="+Reuters20DocMaker.class.getName(),
"doc.add.log.step=30",
"doc.term.vector=false",
"doc.maker.forever=false",
"directory=RAMDirectory",
"doc.stored=false",
"doc.tokenized=false",
"task.max.depth.log=1",
"# ----- alg ",
"{ \"Rounds\"",
" ResetSystemErase",
" "+dis+"CreateIndex", // optionally disable counting here
" { \"AddDocs\" AddDoc > : * ",
" "+dis+" CloseIndex", // optionally disable counting here (with extra blanks)
"}",
"RepSumByName",
};
}
}