Index: contrib/benchmark/CHANGES.txt =================================================================== --- contrib/benchmark/CHANGES.txt (revision 881411) +++ contrib/benchmark/CHANGES.txt (working copy) @@ -3,6 +3,11 @@ The Benchmark contrib package contains code for benchmarking Lucene in a variety of ways. $Id:$ +11/17/2009 + LUCENE-2079: Allow specifying delta thread priority after the "&"; + added log.time.step.msec to print per-time-period counts; fixed + NearRealTimeTask to print reopen times (in msec) of each reopen, at + the end. (Mike McCandless) 11/13/2009 LUCENE-2050: Added ability to run tasks within a serial sequence in Index: contrib/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.java =================================================================== --- contrib/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.java (revision 881411) +++ contrib/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.java (working copy) @@ -123,6 +123,28 @@ assertTrue("elapsed time was " + elapsed + " msec", elapsed <= 1500); } + public void testBGSearchTaskThreads() throws Exception { + String algLines[] = { + "log.time.step.msec = 100", + "ResetSystemErase", + "CreateIndex", + "{ AddDoc } : 1000", + "Optimize", + "CloseIndex", + "OpenReader", + "{", + " [ \"XSearch\" { CountingSearchTest > : * ] : 2 &-1", + " Wait(1.0)", + "}", + "CloseReader", + "RepSumByPref X" + }; + + CountingSearchTestTask.numSearches = 0; + execBenchmark(algLines); + assertTrue(CountingSearchTestTask.numSearches > 0); + } + public void testHighlighting() throws Exception { // 1. alg definition (required in every "logic" test) String algLines[] = { 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 881411) +++ contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/utils/Algorithm.java (working copy) @@ -191,12 +191,22 @@ if (currSequence.isParallel()) { throw new Exception("Can only create background tasks within a serial task"); } + stok.nextToken(); + final int deltaPri; + if (stok.ttype != StreamTokenizer.TT_NUMBER) { + stok.pushBack(); + deltaPri = 0; + } else { + // priority + deltaPri = (int) stok.nval; + } + if (prevTask == null) { throw new Exception("& was unexpected"); } else if (prevTask.getRunInBackground()) { throw new Exception("double & was unexpected"); } else { - prevTask.setRunInBackground(); + prevTask.setRunInBackground(deltaPri); } break; Index: contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/NearRealtimeReaderTask.java =================================================================== --- contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/NearRealtimeReaderTask.java (revision 881411) +++ contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/NearRealtimeReaderTask.java (working copy) @@ -20,6 +20,7 @@ import org.apache.lucene.benchmark.byTask.PerfRunData; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexWriter; +import org.apache.lucene.util.ArrayUtil; /** * Spawns a BG thread that periodically (defaults to 3.0 @@ -36,6 +37,9 @@ long pauseMSec = 3000L; + int reopenCount; + int[] reopenTimes = new int[1]; + public NearRealtimeReaderTask(PerfRunData runData) { super(runData); } @@ -65,7 +69,7 @@ // stddev, min/max reopen latencies // Parent sequence sets stopNow - int reopenCount = 0; + reopenCount = 0; while(!stopNow) { long waitForMsec = (long) (pauseMSec - (System.currentTimeMillis() - t)); if (waitForMsec > 0) { @@ -75,12 +79,16 @@ t = System.currentTimeMillis(); final IndexReader newReader = r.reopen(); if (r != newReader) { + final int delay = (int) (System.currentTimeMillis()-t); + if (reopenTimes.length == reopenCount) { + reopenTimes = ArrayUtil.grow(reopenTimes, 1+reopenCount); + } + reopenTimes[reopenCount++] = delay; // TODO: somehow we need to enable warming, here runData.setIndexReader(newReader); // Transfer our reference to runData newReader.decRef(); r = newReader; - reopenCount++; } } @@ -94,6 +102,15 @@ } @Override + public void close() { + System.out.println("NRT reopen times:"); + for(int i=0;i=0;i--) { + if (byTime[i] != 0) { + end = i; + break; + } + } + if (end != -1) { + sb.append(" by time:"); + for(int i=0;i(); + logByTimeMsec = runData.getConfig().get("log.time.step.msec", 0); } @Override @@ -76,6 +80,9 @@ anyExhaustibleTasks |= tasksArray[k] instanceof TaskSequence; } } + if (!parallel && logByTimeMsec != 0 && !letChildReport) { + countsByTime = new int[1]; + } } /** @@ -92,6 +99,8 @@ return repetitions; } + private int[] countsByTime; + public void setRunTime(double sec) throws Exception { runTimeSec = sec; fixedTime = true; @@ -108,9 +117,6 @@ if (isParallel()) { throw new Exception("REPEAT_EXHAUST is not allowed for parallel tasks"); } - if (getRunData().getConfig().get("content.source.forever",true)) { - throw new Exception("REPEAT_EXHAUST requires setting content.source.forever=false"); - } } setSequenceName(); } @@ -167,11 +173,10 @@ initTasksArray(); int count = 0; - final long t0 = System.currentTimeMillis(); - final long runTime = (long) (runTimeSec*1000); List bgTasks = null; + final long t0 = System.currentTimeMillis(); for (int k=0; fixedTime || (repetitions==REPEAT_EXHAUST && !exhausted) || k(); } RunBackgroundTask bgTask = new RunBackgroundTask(task, letChildReport); + bgTask.setPriority(getBackgroundDeltaPriority() + Thread.currentThread().getPriority()); bgTask.start(); bgTasks.add(bgTask); } else { try { - count += task.runAndMaybeStats(letChildReport); + final int inc = task.runAndMaybeStats(letChildReport); + count += inc; + if (countsByTime != null) { + final int slot = (int) ((System.currentTimeMillis()-t0)/logByTimeMsec); + if (slot >= countsByTime.length) { + countsByTime = ArrayUtil.grow(countsByTime, 1+slot); + } + countsByTime[slot] += inc; + } if (anyExhaustibleTasks) updateExhausted(task); } catch (NoMoreDataException e) { @@ -210,6 +224,11 @@ count += bgTask.getCount(); } } + + if (countsByTime != null) { + getRunData().getPoints().getCurrentStats().setCountsByTime(countsByTime, logByTimeMsec); + } + return count; } @@ -218,6 +237,7 @@ long delayStep = (perMin ? 60000 : 1000) /rate; long nextStartTime = System.currentTimeMillis(); int count = 0; + final long t0 = System.currentTimeMillis(); for (int k=0; (repetitions==REPEAT_EXHAUST && !exhausted) || k= countsByTime.length) { + countsByTime = ArrayUtil.grow(countsByTime, 1+slot); + } + countsByTime[slot] += inc; + } + if (anyExhaustibleTasks) updateExhausted(task); } catch (NoMoreDataException e) { @@ -305,6 +334,9 @@ ParallelTask[] runningParallelTasks; private int doParallelTasks() throws Exception { + + final TaskStats stats = getRunData().getPoints().getCurrentStats(); + initTasksArray(); ParallelTask t[] = runningParallelTasks = new ParallelTask[repetitions * tasks.size()]; // prepare threads @@ -323,8 +355,25 @@ for (int i = 0; i < t.length; i++) { t[i].join(); count += t[i].count; + if (t[i].task instanceof TaskSequence) { + TaskSequence sub = (TaskSequence) t[i].task; + if (sub.countsByTime != null) { + if (countsByTime == null) { + countsByTime = new int[sub.countsByTime.length]; + } else if (countsByTime.length < sub.countsByTime.length) { + countsByTime = ArrayUtil.grow(countsByTime, sub.countsByTime.length); + } + for(int j=0;j