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,7 +4,9 @@ The Benchmark contrib package contains code for benchmarking Lucene in a variety
$Id:$ $Id:$
1/24/2008
LUCENE-1136: add ability to not count sub-task doLogic increment
1/23/2008 1/23/2008
LUCENE-1129: ReadTask properly uses the traversalSize value LUCENE-1129: ReadTask properly uses the traversalSize value
LUCENE-1128: Added support for benchmarking the highlighter LUCENE-1128: Added support for benchmarking the highlighter

View File

@ -50,10 +50,10 @@ log.queries=true
ResetSystemErase ResetSystemErase
{ "Populate" { "Populate"
CreateIndex -CreateIndex
{ "MAddDocs" AddDoc > : 2000 { "MAddDocs" AddDoc > : 2000
Optimize -Optimize
CloseIndex -CloseIndex
} }
OpenReader 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. waiting before starting next add, if otherwise rate would exceed 200 adds/min.
</li> </li>
<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 <b>Command names</b>: Each class "AnyNameTask" in the
package org.apache.lucene.benchmark.byTask.tasks, package org.apache.lucene.benchmark.byTask.tasks,
that extends PerfTask, is supported as command "AnyName" that can be 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 String name;
private int depth = 0; private int depth = 0;
private int maxDepthLogStart = 0; private int maxDepthLogStart = 0;
private boolean disableCounting = false;
protected String params = null; protected String params = null;
protected static final String NEW_LINE = System.getProperty("line.separator"); protected static final String NEW_LINE = System.getProperty("line.separator");
@ -81,6 +82,7 @@ public abstract class PerfTask implements Cloneable {
if (!reportStats || shouldNotRecordStats()) { if (!reportStats || shouldNotRecordStats()) {
setup(); setup();
int count = doLogic(); int count = doLogic();
count = disableCounting ? 0 : count;
tearDown(); tearDown();
return count; return count;
} }
@ -88,6 +90,7 @@ public abstract class PerfTask implements Cloneable {
Points pnts = runData.getPoints(); Points pnts = runData.getPoints();
TaskStats ts = pnts.markTaskStart(this,runData.getConfig().getRoundNumber()); TaskStats ts = pnts.markTaskStart(this,runData.getConfig().getRoundNumber());
int count = doLogic(); int count = doLogic();
count = disableCounting ? 0 : count;
pnts.markTaskEnd(ts, count); pnts.markTaskEnd(ts, count);
tearDown(); tearDown();
return count; return count;
@ -153,6 +156,9 @@ public abstract class PerfTask implements Cloneable {
public String toString() { public String toString() {
String padd = getPadding(); String padd = getPadding();
StringBuffer sb = new StringBuffer(padd); StringBuffer sb = new StringBuffer(padd);
if (disableCounting) {
sb.append('-');
}
sb.append(getName()); sb.append(getName());
return sb.toString(); return sb.toString();
} }
@ -227,4 +233,18 @@ public abstract class PerfTask implements Cloneable {
return params; 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 boolean resetExhausted = false;
private PerfTask[] tasksArray; private PerfTask[] tasksArray;
private boolean anyExhaustibleTasks; 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) { public TaskSequence (PerfRunData runData, String name, TaskSequence parent, boolean parallel) {
super(runData); super(runData);
collapsable = (name == null);
name = (name!=null ? name : (parallel ? "Par" : "Seq")); name = (name!=null ? name : (parallel ? "Par" : "Seq"));
setName(name); setName(name);
setSequenceName(); setSequenceName();
@ -338,5 +340,12 @@ public class TaskSequence extends PerfTask {
} }
return res; 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('(');
stok.ordinaryChar(')'); stok.ordinaryChar(')');
stok.ordinaryChar('-');
boolean colonOk = false; boolean colonOk = false;
boolean isDisableCountNextTask = false; // only for primitive tasks
currSequence.setDepth(0); currSequence.setDepth(0);
String taskPackage = PerfTask.class.getPackage().getName() + "."; String taskPackage = PerfTask.class.getPackage().getName() + ".";
@ -65,6 +67,8 @@ public class Algorithm {
String s = stok.sval; String s = stok.sval;
Constructor cnstr = Class.forName(taskPackage+s+"Task").getConstructor(paramClass); Constructor cnstr = Class.forName(taskPackage+s+"Task").getConstructor(paramClass);
PerfTask task = (PerfTask) cnstr.newInstance(paramObj); PerfTask task = (PerfTask) cnstr.newInstance(paramObj);
task.setDisableCounting(isDisableCountNextTask);
isDisableCountNextTask = false;
currSequence.addTask(task); currSequence.addTask(task);
if (task instanceof RepSumByPrefTask) { if (task instanceof RepSumByPrefTask) {
stok.nextToken(); stok.nextToken();
@ -120,7 +124,8 @@ public class Algorithm {
if ((char)stok.ttype == '*') { if ((char)stok.ttype == '*') {
((TaskSequence)prevTask).setRepetitions(TaskSequence.REPEAT_EXHAUST); ((TaskSequence)prevTask).setRepetitions(TaskSequence.REPEAT_EXHAUST);
} else { } 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); ((TaskSequence)prevTask).setRepetitions((int)stok.nval);
} }
// check for rate specification (ops/min) // check for rate specification (ops/min)
@ -184,6 +189,10 @@ public class Algorithm {
currSequence = currSequence.getParent(); currSequence = currSequence.getParent();
break; break;
case '-' :
isDisableCountNextTask = true;
break;
} //switch(c) } //switch(c)
break; break;
@ -196,7 +205,7 @@ public class Algorithm {
} }
// remove redundant top level enclosing sequences // 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(); ArrayList t = sequence.getTasks();
if (t!=null && t.size()==1) { if (t!=null && t.size()==1) {
PerfTask p = (PerfTask) t.get(0); PerfTask p = (PerfTask) t.get(0);
@ -225,7 +234,7 @@ public class Algorithm {
* @throws Exception * @throws Exception
*/ */
public void execute() 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.List;
import java.util.Iterator; 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.DocData;
import org.apache.lucene.benchmark.byTask.feeds.NoMoreDataException; import org.apache.lucene.benchmark.byTask.feeds.NoMoreDataException;
import org.apache.lucene.benchmark.byTask.feeds.ReutersDocMaker; import org.apache.lucene.benchmark.byTask.feeds.ReutersDocMaker;
@ -194,6 +195,7 @@ public class TestPerfTasksLogic extends TestCase {
try { try {
Benchmark benchmark = execBenchmark(algLines); Benchmark benchmark = execBenchmark(algLines);
assertTrue("CountingHighlighterTest should have thrown an exception", false); assertTrue("CountingHighlighterTest should have thrown an exception", false);
assertNotNull(benchmark); // (avoid compile warning on unused variable)
} catch (Exception e) { } catch (Exception e) {
assertTrue(true); assertTrue(true);
} }
@ -311,7 +313,6 @@ public class TestPerfTasksLogic extends TestCase {
"doc.maker=org.apache.lucene.benchmark.byTask.feeds.LineDocMaker", "doc.maker=org.apache.lucene.benchmark.byTask.feeds.LineDocMaker",
"docs.file=" + lineFile.getAbsolutePath().replace('\\', '/'), "docs.file=" + lineFile.getAbsolutePath().replace('\\', '/'),
"doc.maker.forever=false", "doc.maker.forever=false",
"doc.maker.forever=false",
"doc.reuse.fields=false", "doc.reuse.fields=false",
"autocommit=false", "autocommit=false",
"ram.flush.mb=4", "ram.flush.mb=4",
@ -404,7 +405,7 @@ public class TestPerfTasksLogic extends TestCase {
"directory=RAMDirectory", "directory=RAMDirectory",
"doc.stored=false", "doc.stored=false",
"doc.tokenized=false", "doc.tokenized=false",
"debug.level=1", "task.max.depth.log=1",
"# ----- alg ", "# ----- alg ",
"CreateIndex", "CreateIndex",
"{ [ AddDoc]: 4} : * ", "{ [ AddDoc]: 4} : * ",
@ -482,7 +483,7 @@ public class TestPerfTasksLogic extends TestCase {
"directory=RAMDirectory", "directory=RAMDirectory",
"doc.stored=false", "doc.stored=false",
"doc.tokenized=false", "doc.tokenized=false",
"debug.level=1", "task.max.depth.log=1",
"# ----- alg ", "# ----- alg ",
"{ \"Rounds\"", "{ \"Rounds\"",
" ResetSystemErase", " ResetSystemErase",
@ -501,7 +502,7 @@ public class TestPerfTasksLogic extends TestCase {
assertEquals("wrong number of docs in the index!", ndocsExpected, ir.numDocs()); assertEquals("wrong number of docs in the index!", ndocsExpected, ir.numDocs());
ir.close(); ir.close();
} }
/** /**
* Test that we can close IndexWriter with argument "false". * Test that we can close IndexWriter with argument "false".
*/ */
@ -658,7 +659,7 @@ public class TestPerfTasksLogic extends TestCase {
Benchmark benchmark = execBenchmark(algLines); Benchmark benchmark = execBenchmark(algLines);
final IndexWriter writer = benchmark.getRunData().getIndexWriter(); final IndexWriter writer = benchmark.getRunData().getIndexWriter();
assertEquals(2, writer.getMaxBufferedDocs()); 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(3, writer.getMergeFactor());
assertEquals(false, writer.getUseCompoundFile()); assertEquals(false, writer.getUseCompoundFile());
} }
@ -708,4 +709,63 @@ public class TestPerfTasksLogic extends TestCase {
cfsCount++; cfsCount++;
assertEquals(3, 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",
};
}
} }