Index: contrib/benchmark/conf/micro-standard.alg =================================================================== --- contrib/benchmark/conf/micro-standard.alg (revision 614902) +++ contrib/benchmark/conf/micro-standard.alg (working copy) @@ -50,10 +50,10 @@ ResetSystemErase { "Populate" - CreateIndex + -CreateIndex { "MAddDocs" AddDoc > : 2000 - Optimize - CloseIndex + -Optimize + -CloseIndex } OpenReader Index: contrib/benchmark/CHANGES.txt =================================================================== --- contrib/benchmark/CHANGES.txt (revision 614902) +++ contrib/benchmark/CHANGES.txt (working copy) @@ -4,7 +4,9 @@ $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 LUCENE-1128: Added support for benchmarking the highlighter Index: contrib/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.java =================================================================== --- contrib/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.java (revision 614902) +++ contrib/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.java (working copy) @@ -24,6 +24,7 @@ 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 @@ 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 @@ "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 @@ "directory=RAMDirectory", "doc.stored=false", "doc.tokenized=false", - "debug.level=1", + "task.max.depth.log=1", "# ----- alg ", "CreateIndex", "{ [ AddDoc]: 4} : * ", @@ -482,7 +483,7 @@ "directory=RAMDirectory", "doc.stored=false", "doc.tokenized=false", - "debug.level=1", + "task.max.depth.log=1", "# ----- alg ", "{ \"Rounds\"", " ResetSystemErase", @@ -501,7 +502,7 @@ assertEquals("wrong number of docs in the index!", ndocsExpected, ir.numDocs()); ir.close(); } - + /** * Test that we can close IndexWriter with argument "false". */ @@ -658,7 +659,7 @@ 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 @@ 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", + }; + } + } Index: contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/utils/Algorithm.java =================================================================== --- contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/utils/Algorithm.java (revision 614902) +++ contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/utils/Algorithm.java (working copy) @@ -51,7 +51,9 @@ 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 @@ 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 @@ 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 @@ currSequence = currSequence.getParent(); break; + case '-' : + isDisableCountNextTask = true; + break; + } //switch(c) break; @@ -196,7 +205,7 @@ } // 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 @@ * @throws Exception */ public void execute() throws Exception { - sequence.doLogic(); + sequence.runAndMaybeStats(true); } /** Index: contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/PerfTask.java =================================================================== --- contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/PerfTask.java (revision 614902) +++ contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/PerfTask.java (working copy) @@ -41,6 +41,7 @@ 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 @@ if (!reportStats || shouldNotRecordStats()) { setup(); int count = doLogic(); + count = disableCounting ? 0 : count; tearDown(); return count; } @@ -88,6 +90,7 @@ 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 String toString() { String padd = getPadding(); StringBuffer sb = new StringBuffer(padd); + if (disableCounting) { + sb.append('-'); + } sb.append(getName()); return sb.toString(); } @@ -227,4 +233,18 @@ 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; + } + } Index: contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/TaskSequence.java =================================================================== --- contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/TaskSequence.java (revision 614902) +++ contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/TaskSequence.java (working copy) @@ -40,9 +40,11 @@ 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(); @@ -338,5 +340,12 @@ } return res; } + + /** + * Return true if can be collapsed in case it is outermost sequence + */ + public boolean isCollapsable() { + return collapsable; + } } Index: contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/package.html =================================================================== --- contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/package.html (revision 614902) +++ contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/package.html (working copy) @@ -290,6 +290,15 @@ waiting before starting next add, if otherwise rate would exceed 200 adds/min.
  • + Disable Counting: 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 Results record counting clarified for more details.) + It is possible to disable counting for a task by preceding it with -. +
    Example - -CreateIndex - would count 0 while + the default behavior for CreateIndex is to count 1. +
  • +
  • Command names: Each class "AnyNameTask" in the package org.apache.lucene.benchmark.byTask.tasks, that extends PerfTask, is supported as command "AnyName" that can be