bartoszfidrysiak commented on code in PR #4621: URL: https://github.com/apache/solr/pull/4621#discussion_r3558088398
########## changelog/unreleased/SOLR-18304-fix-collapse-on-string-performance.yml: ########## @@ -0,0 +1,7 @@ +title: Fix collapse on String performance regression due to Lucene upgrade +type: Review Comment: Done ########## solr/benchmark/src/java/org/apache/solr/bench/search/CollapsingSearch.java: ########## @@ -0,0 +1,230 @@ +/* + * 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.bench.search; + +import java.io.IOException; +import java.time.Instant; +import java.time.format.DateTimeFormatter; +import java.util.Locale; +import java.util.Random; +import java.util.UUID; +import java.util.concurrent.TimeUnit; +import org.apache.solr.bench.BaseBenchState; +import org.apache.solr.bench.SolrBenchState; +import org.apache.solr.client.solrj.SolrServerException; +import org.apache.solr.client.solrj.request.CollectionAdminRequest; +import org.apache.solr.client.solrj.request.QueryRequest; +import org.apache.solr.client.solrj.request.SolrQuery; +import org.apache.solr.client.solrj.request.UpdateRequest; +import org.apache.solr.common.SolrInputDocument; +import org.apache.solr.common.params.CommonParams; +import org.apache.solr.common.util.NamedList; +import org.openjdk.jmh.annotations.Benchmark; +import org.openjdk.jmh.annotations.BenchmarkMode; +import org.openjdk.jmh.annotations.Fork; +import org.openjdk.jmh.annotations.Level; +import org.openjdk.jmh.annotations.Measurement; +import org.openjdk.jmh.annotations.Mode; +import org.openjdk.jmh.annotations.OutputTimeUnit; +import org.openjdk.jmh.annotations.Param; +import org.openjdk.jmh.annotations.Scope; +import org.openjdk.jmh.annotations.Setup; +import org.openjdk.jmh.annotations.State; +import org.openjdk.jmh.annotations.TearDown; +import org.openjdk.jmh.annotations.Threads; +import org.openjdk.jmh.annotations.Warmup; + +@Fork(value = 1) +@Warmup(time = 5, iterations = 5) +@Measurement(time = 15, iterations = 5) +@BenchmarkMode(Mode.AverageTime) +@OutputTimeUnit(TimeUnit.MILLISECONDS) +@Threads(value = 1) +public class CollapsingSearch { + + static final String COLLECTION = "collapse_bench"; + + @State(Scope.Benchmark) + public static class BenchState { + + @Param({"2000000"}) + int numDocs; + + @Param({"100000"}) + int numGroups; + + @Param({"1", "10"}) + int numSegments; + + final QueryRequest qSimple = + new QueryRequest(new SolrQuery("q", "*:*", "rows", "10", "cache", "false")); + + final QueryRequest qCollapseWithoutSort = + new QueryRequest( + new SolrQuery( + "q", "*:*", + "fq", "{!collapse field=group_s_dv cache=false}", + "rows", "10", + "cache", "false")); + + final QueryRequest qCollapseByStr = + new QueryRequest( + new SolrQuery( + "q", "*:*", + "fq", "{!collapse field=group_s_dv sort='str_s_dv asc' cache=false}", + "rows", "10", + "cache", "false")); + + final QueryRequest qCollapseByDate = + new QueryRequest( + new SolrQuery( + "q", "*:*", + "fq", "{!collapse field=group_s_dv sort='date_dt_dv asc' cache=false}", + "rows", "10", + "cache", "false")); + + final QueryRequest qCollapseByLong = + new QueryRequest( + new SolrQuery( + "q", "*:*", + "fq", "{!collapse field=group_s_dv sort='long_l_dv asc' cache=false}", + "rows", "10", + "cache", "false")); + + final QueryRequest qCollapseByDateAndStr = + new QueryRequest( + new SolrQuery( + "q", "*:*", + "fq", + "{!collapse field=group_s_dv sort='date_dt_dv asc, str_s_dv asc' cache=false}", + "rows", "10", + "cache", "false")); + + @Setup(Level.Trial) + public void setupTrial(SolrBenchState miniClusterState) throws Exception { + System.setProperty("commitwithin.softcommit", "false"); + miniClusterState.startSolr(1); + miniClusterState.createCollection(COLLECTION, 1, 1); + + indexDocs(miniClusterState); + miniClusterState.forceMerge(COLLECTION, numSegments); + + int actualSegments = getActualSegmentCount(miniClusterState); + BaseBenchState.log( + "CollapsingSearch ready: numDocs=" + + numDocs + + " numGroups=" + + numGroups + + " numSegments(requested)=" + + numSegments + + " numSegments(actual)=" + + actualSegments); + } + + @Setup(Level.Iteration) + public void setupIteration(SolrBenchState miniClusterState) + throws SolrServerException, IOException { + CollectionAdminRequest.Reload reload = CollectionAdminRequest.reloadCollection(COLLECTION); + miniClusterState.client.request(reload); + } + + @TearDown(Level.Trial) + public void teardown(SolrBenchState miniClusterState) throws Exception { + CollectionAdminRequest.deleteCollection(COLLECTION).process(miniClusterState.client); + } + + private int pickGroup(int docId) { + return docId % numGroups; + } + + private int getActualSegmentCount(SolrBenchState state) + throws SolrServerException, IOException { + SolrQuery lukeQuery = new SolrQuery(); Review Comment: Done -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
