Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

LUCENE-1243: Added new benchmark tasks

Grant Ingersolldadaebc2907a
diff --git a/contrib/benchmark/CHANGES.txt b/contrib/benchmark/CHANGES.txt
index 629d583bcbf..4622711b908 100644
--- a/contrib/benchmark/CHANGES.txt
+++ b/contrib/benchmark/CHANGES.txt
@@ -4,6 +4,9 @@ The Benchmark contrib package contains code for benchmarking Lucene in a variety
$Id:$
+9/9/08
+ LUCENE-1243: Added new sorting benchmark capabilities. Also Reopen and commit tasks. (Mark Miller via Grant Ingersoll)
+
5/10/08
LUCENE-1090: remove relative paths assumptions from benchmark code.
Only build.xml was modified: work-dir definition must remain so
diff --git a/contrib/benchmark/conf/sort-standard.alg b/contrib/benchmark/conf/sort-standard.alg
new file mode 100644
index 00000000000..029962d5904
--- /dev/null
+++ b/contrib/benchmark/conf/sort-standard.alg
@@ -0,0 +1,71 @@
+#/**
+# * Licensed to the Apache Software Foundation (ASF) under one or more
+# * contributor license agreements. See the NOTICE file distributed with
+# * this work for additional information regarding copyright ownership.
+# * The ASF licenses this file to You under the Apache License, Version 2.0
+# * (the "License"); you may not use this file except in compliance with
+# * the License. You may obtain a copy of the License at
+# *
+# * http://www.apache.org/licenses/LICENSE-2.0
+# *
+# * Unless required by applicable law or agreed to in writing, software
+# * distributed under the License is distributed on an "AS IS" BASIS,
+# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# * See the License for the specific language governing permissions and
+# * limitations under the License.
+# */
+# -------------------------------------------------------------------------------------
+# multi val params are iterated by NewRound's, added to reports, start with column name.
+
+merge.factor=mrg:50
+compound=false
+
+sort.rng=20000:10000:20000:10000
+
+analyzer=org.apache.lucene.analysis.standard.StandardAnalyzer
+directory=FSDirectory
+#directory=RamDirectory
+
+doc.stored=true
+doc.tokenized=true
+doc.term.vector=false
+doc.add.log.step=100000
+
+docs.dir=reuters-out
+
+doc.maker=org.apache.lucene.benchmark.byTask.feeds.SortableSimpleDocMaker
+
+query.maker=org.apache.lucene.benchmark.byTask.feeds.SimpleQueryMaker
+
+# task at this depth or less would print when they start
+task.max.depth.log=2
+
+log.queries=true
+# -------------------------------------------------------------------------------------
+
+{ "Rounds"
+ { "Run"
+ ResetSystemErase
+
+ { "Populate"
+ -CreateIndex
+ { "MAddDocs" AddDoc(100) > : 500000
+ -Optimize
+ -CloseIndex
+ }
+
+ { "TestSortSpeed"
+ OpenReader
+ { "LoadFieldCacheAndSearch" SearchWithSort(sort_field:int) > : 1
+ { "SearchWithSort" SearchWithSort(sort_field) > : 5000
+ CloseReader
+
+ }
+
+ NewRound
+ } : 4
+
+}
+
+RepSumByName
+
diff --git a/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/SortableSimpleDocMaker.java b/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/SortableSimpleDocMaker.java
new file mode 100644
index 00000000000..24c2f12be57
--- /dev/null
+++ b/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/SortableSimpleDocMaker.java
@@ -0,0 +1,38 @@
+package org.apache.lucene.benchmark.byTask.feeds;
+
+import java.util.Properties;
+import java.util.Random;
+
+import org.apache.lucene.benchmark.byTask.utils.Config;
+
+/**
+ * Adds fields appropriate for sorting.
+ *
+ */
+public class SortableSimpleDocMaker extends SimpleDocMaker {
+ private int sortRange;
+
+ protected DocData getNextDocData() throws NoMoreDataException {
+ DocData doc = super.getNextDocData();
+ Properties props = new Properties();
+ props.put("sort_field", Integer.toString(getRandomNumber(0, sortRange)));
+ doc.setProps(props);
+ return doc;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see SimpleDocMaker#setConfig(java.util.Properties)
+ */
+ public void setConfig(Config config) {
+ super.setConfig(config);
+ sortRange = config.get("sort.rng", 20000);
+ }
+
+ private int getRandomNumber(final int low, final int high) {
+ Random r = new Random();
+ int randInt = (Math.abs(r.nextInt()) % (high - low)) + low;
+ return randInt;
+ }
+}
diff --git a/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/CommitIndexTask.java b/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/CommitIndexTask.java
new file mode 100644
index 00000000000..9d48ab6523d
--- /dev/null
+++ b/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/CommitIndexTask.java
@@ -0,0 +1,39 @@
+package org.apache.lucene.benchmark.byTask.tasks;
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.lucene.benchmark.byTask.PerfRunData;
+import org.apache.lucene.index.IndexWriter;
+
+/**
+ * Commits the IndexReader.
+ *
+ */
+public class CommitIndexTask extends PerfTask {
+ public CommitIndexTask(PerfRunData runData) {
+ super(runData);
+ }
+
+ public int doLogic() throws Exception {
+ IndexWriter iw = getRunData().getIndexWriter();
+ if (iw!=null) {
+ iw.commit();
+ }
+
+ return 1;
+ }
+}
diff --git a/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/ReadTask.java b/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/ReadTask.java
index 8336b06f7f3..90278df6bf1 100644
--- a/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/ReadTask.java
+++ b/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/ReadTask.java
@@ -17,8 +17,15 @@ package org.apache.lucene.benchmark.byTask.tasks;
* limitations under the License.
*/
-import org.apache.lucene.analysis.TokenStream;
+import java.io.IOException;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
import org.apache.lucene.analysis.Analyzer;
+import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.benchmark.byTask.PerfRunData;
import org.apache.lucene.benchmark.byTask.feeds.QueryMaker;
import org.apache.lucene.document.Document;
@@ -27,12 +34,14 @@ import org.apache.lucene.index.IndexReader;
import org.apache.lucene.search.Hits;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
-import org.apache.lucene.search.highlight.*;
+import org.apache.lucene.search.Sort;
+import org.apache.lucene.search.highlight.Highlighter;
+import org.apache.lucene.search.highlight.QueryScorer;
+import org.apache.lucene.search.highlight.SimpleHTMLFormatter;
+import org.apache.lucene.search.highlight.TextFragment;
+import org.apache.lucene.search.highlight.TokenSources;
import org.apache.lucene.store.Directory;
-import java.io.IOException;
-import java.util.*;
-
/**
* Read index (abstract) task.
@@ -79,7 +88,13 @@ public abstract class ReadTask extends PerfTask {
IndexSearcher searcher = new IndexSearcher(ir);
QueryMaker queryMaker = getQueryMaker();
Query q = queryMaker.makeQuery();
- Hits hits = searcher.search(q);
+ Sort sort = getSort();
+ Hits hits;
+ if(sort != null) {
+ hits = searcher.search(q, sort);
+ } else {
+ hits = searcher.search(q);
+ }
//System.out.println("searched: "+q);
if (withTraverse() && hits != null) {
@@ -139,6 +154,7 @@ public abstract class ReadTask extends PerfTask {
* Return true if search should be performed.
*/
public abstract boolean withSearch();
+
/**
* Return true if warming should be performed.
@@ -200,6 +216,10 @@ public abstract class ReadTask extends PerfTask {
TextFragment[] frag = highlighter.getBestTextFragments(ts, text, mergeContiguous, maxFragments);
return frag != null ? frag.length : 0;
}
+
+ protected Sort getSort() {
+ return null;
+ }
/**
* Define the fields to highlight. Base implementation returns all fields
diff --git a/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/ReopenReaderTask.java b/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/ReopenReaderTask.java
new file mode 100644
index 00000000000..487da4224f6
--- /dev/null
+++ b/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/ReopenReaderTask.java
@@ -0,0 +1,44 @@
+package org.apache.lucene.benchmark.byTask.tasks;
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+import java.io.IOException;
+
+import org.apache.lucene.benchmark.byTask.PerfRunData;
+import org.apache.lucene.index.IndexReader;
+
+/**
+* Reopens IndexReader and closes old IndexReader.
+*
+*/
+public class ReopenReaderTask extends PerfTask {
+ public ReopenReaderTask(PerfRunData runData) {
+ super(runData);
+ }
+
+ public int doLogic() throws IOException {
+ IndexReader ir = getRunData().getIndexReader();
+ IndexReader or = ir;
+ IndexReader nr = ir.reopen();
+ if(nr != or) {
+ getRunData().setIndexReader(nr);
+ or.close();
+ }
+ return 1;
+ }
+}
diff --git a/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/SearchWithSortTask.java b/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/SearchWithSortTask.java
new file mode 100644
index 00000000000..387443efefb
--- /dev/null
+++ b/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/SearchWithSortTask.java
@@ -0,0 +1,109 @@
+package org.apache.lucene.benchmark.byTask.tasks;
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.lucene.benchmark.byTask.PerfRunData;
+import org.apache.lucene.benchmark.byTask.feeds.QueryMaker;
+import org.apache.lucene.search.Sort;
+import org.apache.lucene.search.SortField;
+
+/**
+ * Does sort search on specified field.
+ *
+ */
+public class SearchWithSortTask extends ReadTask {
+
+ private Sort sort;
+
+ public SearchWithSortTask(PerfRunData runData) {
+ super(runData);
+ }
+
+ /**
+ * SortFields: field:type,field:type
+ *
+ * name,byline:int,subject:auto
+ *
+ */
+ public void setParams(String sortField) {
+ super.setParams(sortField);
+ String[] fields = sortField.split(",");
+ SortField[] sortFields = new SortField[fields.length];
+ for (int i = 0; i < fields.length; i++) {
+ String field = fields[i];
+ int index = field.lastIndexOf(":");
+ String fieldName;
+ String typeString;
+ if (index != -1) {
+ fieldName = field.substring(0, index);
+ typeString = field.substring(index, field.length());
+ } else {
+ typeString = "auto";
+ fieldName = field;
+ }
+ int type = getType(typeString);
+ sortFields[i] = new SortField(fieldName, type);
+ }
+ this.sort = new Sort(sortFields);
+ }
+
+ private int getType(String typeString) {
+ int type;
+ if (typeString.equals("float")) {
+ type = SortField.FLOAT;
+ } else if (typeString.equals("int")) {
+ type = SortField.INT;
+ } else if (typeString.equals("string")) {
+ type = SortField.STRING;
+ } else {
+ type = SortField.AUTO;
+ }
+ return type;
+ }
+
+ public boolean supportsParams() {
+ return true;
+ }
+
+ public QueryMaker getQueryMaker() {
+ return getRunData().getQueryMaker(this);
+ }
+
+ public boolean withRetrieve() {
+ return false;
+ }
+
+ public boolean withSearch() {
+ return true;
+ }
+
+ public boolean withTraverse() {
+ return false;
+ }
+
+ public boolean withWarm() {
+ return false;
+ }
+
+ public Sort getSort() {
+ if (sort == null) {
+ throw new IllegalStateException("No sort field was set");
+ }
+ return sort;
+ }
+
+}