2
* Licensed to the Apache Software Foundation (ASF) under one or more
3
* contributor license agreements. See the NOTICE file distributed with
4
* this work for additional information regarding copyright ownership.
5
* The ASF licenses this file to You under the Apache License, Version 2.0
6
* (the "License"); you may not use this file except in compliance with
7
* the License. You may obtain a copy of the License at
9
* http://www.apache.org/licenses/LICENSE-2.0
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
18
package org.apache.solr.search;
20
import org.apache.lucene.index.Term;
21
import org.apache.lucene.search.*;
22
import org.apache.solr.util.AbstractSolrTestCase;
23
import org.apache.solr.request.SolrQueryRequest;
24
import org.apache.solr.response.SolrQueryResponse;
25
import org.apache.solr.update.processor.UpdateRequestProcessorChain;
26
import org.apache.solr.update.processor.UpdateRequestProcessor;
27
import org.apache.solr.update.AddUpdateCommand;
28
import org.apache.solr.common.SolrInputDocument;
31
import java.io.IOException;
34
* @version $Id: TestSearchPerf.java 1140724 2011-06-28 17:00:20Z yonik $
36
public class TestSearchPerf extends AbstractSolrTestCase {
39
public String getSchemaFile() { return "schema11.xml"; }
41
public String getSolrConfigFile() { return "solrconfig.xml"; }
44
public void setUp() throws Exception {
48
public void tearDown() throws Exception {
53
return String.format("%08d", tnum);
56
Random r = new Random(0); // specific seed for reproducible perf testing
58
void createIndex(int nDocs) {
61
for (int i=0; i<nDocs; i++) {
62
assertU(adoc("id", Float.toString(i)
64
// ,"foo2_s",t(r.nextInt(2))
65
// ,"foo4_s",t(r.nextInt(3))
66
,"foomany_s",t(r.nextInt(nDocs*10))
69
// assertU(optimize()); // squeeze out any possible deleted docs
74
// Skip encoding for updating the index
75
void createIndex2(int nDocs, String... fields) throws IOException {
76
Set<String> fieldSet = new HashSet<String>(Arrays.asList(fields));
78
SolrQueryRequest req = lrf.makeRequest();
79
SolrQueryResponse rsp = new SolrQueryResponse();
80
UpdateRequestProcessorChain processorChain = req.getCore().getUpdateProcessingChain(null);
81
UpdateRequestProcessor processor = processorChain.createProcessor(req, rsp);
83
boolean foomany_s = fieldSet.contains("foomany_s");
84
boolean foo1_s = fieldSet.contains("foo1_s");
85
boolean foo2_s = fieldSet.contains("foo2_s");
86
boolean foo4_s = fieldSet.contains("foo4_s");
87
boolean foo8_s = fieldSet.contains("foo8_s");
88
boolean t10_100_ws = fieldSet.contains("t10_100_ws");
91
for (int i=0; i<nDocs; i++) {
92
SolrInputDocument doc = new SolrInputDocument();
93
doc.addField("id",Float.toString(i));
95
doc.addField("foomany_s",t(r.nextInt(nDocs*10)));
98
doc.addField("foo1_s",t(0));
101
doc.addField("foo2_s",r.nextInt(2));
104
doc.addField("foo4_s",r.nextInt(4));
107
doc.addField("foo8_s",r.nextInt(8));
110
StringBuilder sb = new StringBuilder(9*100);
111
for (int j=0; j<100; j++) {
113
sb.append(t(r.nextInt(10)));
115
doc.addField("t10_100_ws", sb.toString());
118
AddUpdateCommand cmd = new AddUpdateCommand();
120
processor.processAdd(cmd);
127
req = lrf.makeRequest();
128
assertEquals(nDocs, req.getSearcher().maxDoc());
133
int doSetGen(int iter, Query q) throws Exception {
134
SolrQueryRequest req = lrf.makeRequest();
136
SolrIndexSearcher searcher = req.getSearcher();
138
long start = System.currentTimeMillis();
141
for (int i=0; i<iter; i++) {
142
DocSet set = searcher.getDocSetNC(q, null);
146
long end = System.currentTimeMillis();
147
System.out.println("ret="+ret+ " time="+(end-start)+" throughput="+iter*1000/(end-start+1));
150
assertTrue(ret>0); // make sure we did some work
154
int doListGen(int iter, Query q, List<Query> filt, boolean cacheQuery, boolean cacheFilt) throws Exception {
155
SolrQueryRequest req = lrf.makeRequest();
157
SolrIndexSearcher searcher = req.getSearcher();
159
long start = System.currentTimeMillis();
161
// These aren't public in SolrIndexSearcher
162
int NO_CHECK_QCACHE = 0x80000000;
163
int GET_DOCSET = 0x40000000;
164
int NO_CHECK_FILTERCACHE = 0x20000000;
165
int GET_SCORES = 0x01;
168
for (int i=0; i<iter; i++) {
169
DocList l = searcher.getDocList(q, filt, (Sort)null, 0, 10, (cacheQuery?0:NO_CHECK_QCACHE)|(cacheFilt?0:NO_CHECK_FILTERCACHE) );
173
long end = System.currentTimeMillis();
174
System.out.println("ret="+ret+ " time="+(end-start)+" throughput="+iter*1000/(end-start+1));
177
assertTrue(ret>0); // make sure we did some work
181
// prevent complaints by junit
182
public void testEmpty() {
185
public void XtestSetGenerationPerformance() throws Exception {
187
doSetGen(10000, new TermQuery(new Term("foo1_s",t(0))) );
189
BooleanQuery bq = new BooleanQuery();
190
bq.add(new TermQuery(new Term("foo2_s",t(0))), BooleanClause.Occur.SHOULD);
191
bq.add(new TermQuery(new Term("foo2_s",t(1))), BooleanClause.Occur.SHOULD);
195
/** test range query performance */
196
public void XtestRangePerformance() throws Exception {
198
float fractionCovered=1.0f;
201
String u=t((int)(indexSize*10*fractionCovered));
203
SolrQueryRequest req = lrf.makeRequest();
204
QParser parser = QParser.getParser("foomany_s:[" + l + " TO " + u + "]", null, req);
205
Query range = parser.getQuery();
207
QParser parser2 = QParser.getParser("{!frange l="+l+" u="+u+"}foomany_s", null, req);
208
Query frange = parser2.getQuery();
211
createIndex2(indexSize,"foomany_s");
214
doSetGen(1, frange); // load field cache
216
doSetGen(100, range);
217
doSetGen(10000, frange);
220
/** test range query performance */
221
public void XtestFilteringPerformance() throws Exception {
223
float fractionCovered=.1f;
226
String u=t((int)(indexSize*10*fractionCovered));
228
SolrQueryRequest req = lrf.makeRequest();
230
QParser parser = QParser.getParser("foomany_s:[" + l + " TO " + u + "]", null, req);
231
Query rangeQ = parser.getQuery();
232
List<Query> filters = new ArrayList<Query>();
236
parser = QParser.getParser("{!dismax qf=t10_100_ws pf=t10_100_ws ps=20}"+ t(0) + ' ' + t(1) + ' ' + t(2), null, req);
237
Query q= parser.getQuery();
239
// SolrIndexSearcher searcher = req.getSearcher();
240
// DocSet range = searcher.getDocSet(rangeQ, null);
242
createIndex2(indexSize, "foomany_s", "t10_100_ws");
244
// doListGen(100, q, filters, false, true);
245
doListGen(500, q, filters, false, true);
b'\\ No newline at end of file'