mirror of https://github.com/apache/lucene.git
SOLR-9905: Add NullStream to isolate the performance of the ExportWriter
This commit is contained in:
parent
db9190db93
commit
7dcb557ab7
|
@ -139,7 +139,7 @@ public class StreamHandler extends RequestHandlerBase implements SolrCoreAware,
|
||||||
.withFunctionName("classify", ClassifyStream.class)
|
.withFunctionName("classify", ClassifyStream.class)
|
||||||
.withFunctionName("fetch", FetchStream.class)
|
.withFunctionName("fetch", FetchStream.class)
|
||||||
.withFunctionName("executor", ExecutorStream.class)
|
.withFunctionName("executor", ExecutorStream.class)
|
||||||
|
.withFunctionName("null", NullStream.class)
|
||||||
// metrics
|
// metrics
|
||||||
.withFunctionName("min", MinMetric.class)
|
.withFunctionName("min", MinMetric.class)
|
||||||
.withFunctionName("max", MaxMetric.class)
|
.withFunctionName("max", MaxMetric.class)
|
||||||
|
|
|
@ -0,0 +1,155 @@
|
||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
package org.apache.solr.client.solrj.io.stream;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import org.apache.solr.client.solrj.io.Tuple;
|
||||||
|
import org.apache.solr.client.solrj.io.comp.StreamComparator;
|
||||||
|
import org.apache.solr.client.solrj.io.stream.expr.Explanation;
|
||||||
|
import org.apache.solr.client.solrj.io.stream.expr.Explanation.ExpressionType;
|
||||||
|
import org.apache.solr.client.solrj.io.stream.expr.Expressible;
|
||||||
|
import org.apache.solr.client.solrj.io.stream.expr.StreamExplanation;
|
||||||
|
import org.apache.solr.client.solrj.io.stream.expr.StreamExpression;
|
||||||
|
import org.apache.solr.client.solrj.io.stream.expr.StreamFactory;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The NullStream Iterates over a TupleStream and eats the tuples. It returns the tuple count in the EOF tuple.
|
||||||
|
* Because the NullStreaam eats all the Tuples it see's it can be used as a simple tool for performance analysis of
|
||||||
|
* underlying streams.
|
||||||
|
**/
|
||||||
|
|
||||||
|
public class NullStream extends TupleStream implements Expressible {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1;
|
||||||
|
|
||||||
|
private TupleStream stream;
|
||||||
|
private long count;
|
||||||
|
private long start;
|
||||||
|
private Tuple eof;
|
||||||
|
|
||||||
|
public NullStream(TupleStream tupleStream) throws IOException {
|
||||||
|
init(tupleStream);
|
||||||
|
}
|
||||||
|
|
||||||
|
public NullStream(StreamExpression expression, StreamFactory factory) throws IOException {
|
||||||
|
// grab all parameters out
|
||||||
|
List<StreamExpression> streamExpressions = factory.getExpressionOperandsRepresentingTypes(expression, Expressible.class, TupleStream.class);
|
||||||
|
TupleStream stream = factory.constructStream(streamExpressions.get(0));
|
||||||
|
|
||||||
|
init(stream);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void init(TupleStream tupleStream) throws IOException{
|
||||||
|
this.stream = tupleStream;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StreamExpression toExpression(StreamFactory factory) throws IOException{
|
||||||
|
return toExpression(factory, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private StreamExpression toExpression(StreamFactory factory, boolean includeStreams) throws IOException {
|
||||||
|
// function name
|
||||||
|
StreamExpression expression = new StreamExpression(factory.getFunctionName(this.getClass()));
|
||||||
|
|
||||||
|
if(includeStreams){
|
||||||
|
// stream
|
||||||
|
if(stream instanceof Expressible){
|
||||||
|
expression.addParameter(((Expressible)stream).toExpression(factory));
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
throw new IOException("This RankStream contains a non-expressible TupleStream - it cannot be converted to an expression");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
expression.addParameter("<stream>");
|
||||||
|
}
|
||||||
|
|
||||||
|
return expression;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Explanation toExplanation(StreamFactory factory) throws IOException {
|
||||||
|
|
||||||
|
return new StreamExplanation(getStreamNodeId().toString())
|
||||||
|
.withChildren(new Explanation[]{
|
||||||
|
stream.toExplanation(factory)
|
||||||
|
})
|
||||||
|
.withFunctionName(factory.getFunctionName(this.getClass()))
|
||||||
|
.withImplementingClass(this.getClass().getName())
|
||||||
|
.withExpressionType(ExpressionType.STREAM_DECORATOR)
|
||||||
|
.withExpression(toExpression(factory, false).toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStreamContext(StreamContext context) {
|
||||||
|
this.stream.setStreamContext(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<TupleStream> children() {
|
||||||
|
List<TupleStream> l = new ArrayList<TupleStream>();
|
||||||
|
l.add(stream);
|
||||||
|
return l;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void open() throws IOException {
|
||||||
|
start = new Date().getTime();
|
||||||
|
count = 0;
|
||||||
|
stream.open();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void close() throws IOException {
|
||||||
|
stream.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Tuple read() throws IOException {
|
||||||
|
|
||||||
|
if(eof != null) {
|
||||||
|
return eof;
|
||||||
|
}
|
||||||
|
|
||||||
|
while(true) {
|
||||||
|
Tuple tuple = stream.read();
|
||||||
|
if(tuple.EOF) {
|
||||||
|
eof = tuple;
|
||||||
|
long end = new Date().getTime();
|
||||||
|
Tuple t = new Tuple(new HashMap());
|
||||||
|
t.put("nullCount", count);
|
||||||
|
t.put("timer", end-start);
|
||||||
|
return t;
|
||||||
|
} else {
|
||||||
|
++count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Return the stream sort - ie, the order in which records are returned */
|
||||||
|
public StreamComparator getStreamSort(){
|
||||||
|
return stream.getStreamSort();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCost() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -373,6 +373,71 @@ public class StreamExpressionTest extends SolrCloudTestCase {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNullStream() throws Exception {
|
||||||
|
|
||||||
|
new UpdateRequest()
|
||||||
|
.add(id, "0", "a_s", "hello0", "a_i", "0", "a_f", "0")
|
||||||
|
.add(id, "2", "a_s", "hello2", "a_i", "2", "a_f", "0")
|
||||||
|
.add(id, "3", "a_s", "hello3", "a_i", "3", "a_f", "3")
|
||||||
|
.add(id, "4", "a_s", "hello4", "a_i", "4", "a_f", "4")
|
||||||
|
.add(id, "1", "a_s", "hello1", "a_i", "1", "a_f", "1")
|
||||||
|
.add(id, "5", "a_s", "hello1", "a_i", "1", "a_f", "2")
|
||||||
|
.commit(cluster.getSolrClient(), COLLECTIONORALIAS);
|
||||||
|
|
||||||
|
StreamExpression expression;
|
||||||
|
TupleStream stream;
|
||||||
|
List<Tuple> tuples;
|
||||||
|
|
||||||
|
StreamFactory factory = new StreamFactory()
|
||||||
|
.withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())
|
||||||
|
.withFunctionName("search", CloudSolrStream.class)
|
||||||
|
.withFunctionName("null", NullStream.class);
|
||||||
|
|
||||||
|
// Basic test
|
||||||
|
stream = factory.constructStream("null(search(" + COLLECTIONORALIAS + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc\"), by=\"a_i asc\")");
|
||||||
|
tuples = getTuples(stream);
|
||||||
|
assertTrue(tuples.size() == 1);
|
||||||
|
assertTrue(tuples.get(0).getLong("nullCount") == 6);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testParallelNullStream() throws Exception {
|
||||||
|
|
||||||
|
new UpdateRequest()
|
||||||
|
.add(id, "0", "a_s", "hello0", "a_i", "0", "a_f", "0")
|
||||||
|
.add(id, "2", "a_s", "hello2", "a_i", "2", "a_f", "0")
|
||||||
|
.add(id, "3", "a_s", "hello3", "a_i", "3", "a_f", "3")
|
||||||
|
.add(id, "4", "a_s", "hello4", "a_i", "4", "a_f", "4")
|
||||||
|
.add(id, "1", "a_s", "hello1", "a_i", "1", "a_f", "1")
|
||||||
|
.add(id, "5", "a_s", "hello1", "a_i", "1", "a_f", "2")
|
||||||
|
.commit(cluster.getSolrClient(), COLLECTIONORALIAS);
|
||||||
|
|
||||||
|
StreamExpression expression;
|
||||||
|
TupleStream stream;
|
||||||
|
List<Tuple> tuples;
|
||||||
|
|
||||||
|
StreamFactory factory = new StreamFactory()
|
||||||
|
.withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())
|
||||||
|
.withFunctionName("search", CloudSolrStream.class)
|
||||||
|
.withFunctionName("null", NullStream.class)
|
||||||
|
.withFunctionName("parallel", ParallelStream.class);
|
||||||
|
|
||||||
|
// Basic test
|
||||||
|
stream = factory.constructStream("parallel(" + COLLECTIONORALIAS + ", workers=2, sort=\"nullCount desc\", null(search(" + COLLECTIONORALIAS + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc\", partitionKeys=id), by=\"a_i asc\"))");
|
||||||
|
tuples = getTuples(stream);
|
||||||
|
assertTrue(tuples.size() == 2);
|
||||||
|
long nullCount = 0;
|
||||||
|
for(Tuple t : tuples) {
|
||||||
|
nullCount += t.getLong("nullCount");
|
||||||
|
}
|
||||||
|
|
||||||
|
assertEquals(nullCount, 6L);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNulls() throws Exception {
|
public void testNulls() throws Exception {
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue