mirror of https://github.com/apache/lucene.git
LUCENE-1243: Added new benchmark tasks
git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@693495 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
5147f0563f
commit
dadaebc290
|
@ -4,6 +4,9 @@ The Benchmark contrib package contains code for benchmarking Lucene in a variety
|
||||||
|
|
||||||
$Id:$
|
$Id:$
|
||||||
|
|
||||||
|
9/9/08
|
||||||
|
LUCENE-1243: Added new sorting benchmark capabilities. Also Reopen and commit tasks. (Mark Miller via Grant Ingersoll)
|
||||||
|
|
||||||
5/10/08
|
5/10/08
|
||||||
LUCENE-1090: remove relative paths assumptions from benchmark code.
|
LUCENE-1090: remove relative paths assumptions from benchmark code.
|
||||||
Only build.xml was modified: work-dir definition must remain so
|
Only build.xml was modified: work-dir definition must remain so
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -17,8 +17,15 @@ package org.apache.lucene.benchmark.byTask.tasks;
|
||||||
* limitations under the License.
|
* 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.Analyzer;
|
||||||
|
import org.apache.lucene.analysis.TokenStream;
|
||||||
import org.apache.lucene.benchmark.byTask.PerfRunData;
|
import org.apache.lucene.benchmark.byTask.PerfRunData;
|
||||||
import org.apache.lucene.benchmark.byTask.feeds.QueryMaker;
|
import org.apache.lucene.benchmark.byTask.feeds.QueryMaker;
|
||||||
import org.apache.lucene.document.Document;
|
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.Hits;
|
||||||
import org.apache.lucene.search.IndexSearcher;
|
import org.apache.lucene.search.IndexSearcher;
|
||||||
import org.apache.lucene.search.Query;
|
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 org.apache.lucene.store.Directory;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read index (abstract) task.
|
* Read index (abstract) task.
|
||||||
|
@ -79,7 +88,13 @@ public abstract class ReadTask extends PerfTask {
|
||||||
IndexSearcher searcher = new IndexSearcher(ir);
|
IndexSearcher searcher = new IndexSearcher(ir);
|
||||||
QueryMaker queryMaker = getQueryMaker();
|
QueryMaker queryMaker = getQueryMaker();
|
||||||
Query q = queryMaker.makeQuery();
|
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);
|
//System.out.println("searched: "+q);
|
||||||
|
|
||||||
if (withTraverse() && hits != null) {
|
if (withTraverse() && hits != null) {
|
||||||
|
@ -140,6 +155,7 @@ public abstract class ReadTask extends PerfTask {
|
||||||
*/
|
*/
|
||||||
public abstract boolean withSearch();
|
public abstract boolean withSearch();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return true if warming should be performed.
|
* Return true if warming should be performed.
|
||||||
*/
|
*/
|
||||||
|
@ -201,6 +217,10 @@ public abstract class ReadTask extends PerfTask {
|
||||||
return frag != null ? frag.length : 0;
|
return frag != null ? frag.length : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected Sort getSort() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Define the fields to highlight. Base implementation returns all fields
|
* Define the fields to highlight. Base implementation returns all fields
|
||||||
* @param document The Document
|
* @param document The Document
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue