LUCENE-2377: Enable the use of NoMergePolicy and NoMergeScheduler by Benchmark

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@931502 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Shai Erera 2010-04-07 11:03:32 +00:00
parent ec8bcf48d1
commit a37ac8ba7d
3 changed files with 54 additions and 22 deletions

View File

@ -2,6 +2,10 @@ Lucene Benchmark Contrib Change Log
The Benchmark contrib package contains code for benchmarking Lucene in a variety of ways. The Benchmark contrib package contains code for benchmarking Lucene in a variety of ways.
4/07/2010
LUCENE-2377: Enable the use of NoMergePolicy and NoMergeScheduler by
CreateIndexTask. (Shai Erera)
3/28/2010 3/28/2010
LUCENE-2353: Fixed bug in Config where Windows absolute path property values LUCENE-2353: Fixed bug in Config where Windows absolute path property values
were incorrectly handled (Shai Erera) were incorrectly handled (Shai Erera)

View File

@ -25,6 +25,8 @@ import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.index.MergeScheduler; import org.apache.lucene.index.MergeScheduler;
import org.apache.lucene.index.ConcurrentMergeScheduler; import org.apache.lucene.index.ConcurrentMergeScheduler;
import org.apache.lucene.index.MergePolicy; import org.apache.lucene.index.MergePolicy;
import org.apache.lucene.index.NoMergePolicy;
import org.apache.lucene.index.NoMergeScheduler;
import org.apache.lucene.index.IndexWriterConfig.OpenMode; import org.apache.lucene.index.IndexWriterConfig.OpenMode;
import org.apache.lucene.util.Version; import org.apache.lucene.util.Version;
@ -70,34 +72,42 @@ public class CreateIndexTask extends PerfTask {
final String mergeScheduler = config.get("merge.scheduler", final String mergeScheduler = config.get("merge.scheduler",
"org.apache.lucene.index.ConcurrentMergeScheduler"); "org.apache.lucene.index.ConcurrentMergeScheduler");
try { if (mergeScheduler.equals(NoMergeScheduler.class.getName())) {
writer.setMergeScheduler(Class.forName(mergeScheduler).asSubclass(MergeScheduler.class).newInstance()); writer.setMergeScheduler(NoMergeScheduler.INSTANCE);
} catch (Exception e) { } else {
throw new RuntimeException("unable to instantiate class '" + mergeScheduler + "' as merge scheduler", e); try {
} writer.setMergeScheduler(Class.forName(mergeScheduler).asSubclass(MergeScheduler.class).newInstance());
} catch (Exception e) {
if (mergeScheduler.equals("org.apache.lucene.index.ConcurrentMergeScheduler")) { throw new RuntimeException("unable to instantiate class '" + mergeScheduler + "' as merge scheduler", e);
ConcurrentMergeScheduler cms = (ConcurrentMergeScheduler) writer.getMergeScheduler();
int v = config.get("concurrent.merge.scheduler.max.thread.count", -1);
if (v != -1) {
cms.setMaxThreadCount(v);
} }
v = config.get("concurrent.merge.scheduler.max.merge.count", -1);
if (v != -1) { if (mergeScheduler.equals("org.apache.lucene.index.ConcurrentMergeScheduler")) {
cms.setMaxMergeCount(v); ConcurrentMergeScheduler cms = (ConcurrentMergeScheduler) writer.getMergeScheduler();
int v = config.get("concurrent.merge.scheduler.max.thread.count", -1);
if (v != -1) {
cms.setMaxThreadCount(v);
}
v = config.get("concurrent.merge.scheduler.max.merge.count", -1);
if (v != -1) {
cms.setMaxMergeCount(v);
}
} }
} }
final String mergePolicy = config.get("merge.policy", final String mergePolicy = config.get("merge.policy",
"org.apache.lucene.index.LogByteSizeMergePolicy"); "org.apache.lucene.index.LogByteSizeMergePolicy");
try { boolean isCompound = config.get("compound", true);
writer.setMergePolicy(Class.forName(mergePolicy).asSubclass(MergePolicy.class).newInstance()); if (mergePolicy.equals(NoMergePolicy.class.getName())) {
} catch (Exception e) { writer.setMergePolicy(isCompound ? NoMergePolicy.COMPOUND_FILES : NoMergePolicy.NO_COMPOUND_FILES);
throw new RuntimeException("unable to instantiate class '" + mergePolicy + "' as merge policy", e); } else {
try {
writer.setMergePolicy(Class.forName(mergePolicy).asSubclass(MergePolicy.class).newInstance());
} catch (Exception e) {
throw new RuntimeException("unable to instantiate class '" + mergePolicy + "' as merge policy", e);
}
writer.setUseCompoundFile(isCompound);
writer.setMergeFactor(config.get("merge.factor",OpenIndexTask.DEFAULT_MERGE_PFACTOR));
} }
writer.setUseCompoundFile(config.get("compound",true));
writer.setMergeFactor(config.get("merge.factor",OpenIndexTask.DEFAULT_MERGE_PFACTOR));
writer.setMaxFieldLength(config.get("max.field.length",OpenIndexTask.DEFAULT_MAX_FIELD_LENGTH)); writer.setMaxFieldLength(config.get("max.field.length",OpenIndexTask.DEFAULT_MAX_FIELD_LENGTH));
final double ramBuffer = config.get("ram.flush.mb",OpenIndexTask.DEFAULT_RAM_FLUSH_MB); final double ramBuffer = config.get("ram.flush.mb",OpenIndexTask.DEFAULT_RAM_FLUSH_MB);

View File

@ -25,6 +25,8 @@ import java.util.Properties;
import org.apache.lucene.benchmark.BenchmarkTestCase; import org.apache.lucene.benchmark.BenchmarkTestCase;
import org.apache.lucene.benchmark.byTask.PerfRunData; import org.apache.lucene.benchmark.byTask.PerfRunData;
import org.apache.lucene.benchmark.byTask.utils.Config; import org.apache.lucene.benchmark.byTask.utils.Config;
import org.apache.lucene.index.NoMergePolicy;
import org.apache.lucene.index.NoMergeScheduler;
/** Tests the functionality of {@link CreateIndexTask}. */ /** Tests the functionality of {@link CreateIndexTask}. */
public class CreateIndexTaskTest extends BenchmarkTestCase { public class CreateIndexTaskTest extends BenchmarkTestCase {
@ -33,7 +35,9 @@ public class CreateIndexTaskTest extends BenchmarkTestCase {
Properties props = new Properties(); Properties props = new Properties();
props.setProperty("print.props", "false"); // don't print anything props.setProperty("print.props", "false"); // don't print anything
props.setProperty("directory", "RAMDirectory"); props.setProperty("directory", "RAMDirectory");
props.setProperty("writer.info.stream", infoStreamValue); if (infoStreamValue != null) {
props.setProperty("writer.info.stream", infoStreamValue);
}
Config config = new Config(props); Config config = new Config(props);
return new PerfRunData(config); return new PerfRunData(config);
} }
@ -77,4 +81,18 @@ public class CreateIndexTaskTest extends BenchmarkTestCase {
assertTrue(outFile.length() > 0); assertTrue(outFile.length() > 0);
} }
public void testNoMergePolicy() throws Exception {
PerfRunData runData = createPerfRunData(null);
runData.getConfig().set("merge.policy", NoMergePolicy.class.getName());
new CreateIndexTask(runData).doLogic();
new CloseIndexTask(runData).doLogic();
}
public void testNoMergeScheduler() throws Exception {
PerfRunData runData = createPerfRunData(null);
runData.getConfig().set("merge.scheduler", NoMergeScheduler.class.getName());
new CreateIndexTask(runData).doLogic();
new CloseIndexTask(runData).doLogic();
}
} }