dsmiley commented on code in PR #4621:
URL: https://github.com/apache/solr/pull/4621#discussion_r3556463479
##########
solr/core/src/java/org/apache/solr/search/CollapsingQParserPlugin.java:
##########
@@ -3696,6 +3722,19 @@ private boolean testAndSetGroupValues(Object[] values,
int contextDoc) throws IO
int testClause = 0;
for (
/* testClause */ ; testClause < numClauses; testClause++) {
+ if (values[testClause] instanceof LazyStringValue) {
+ LazyStringValue headVal = (LazyStringValue) values[testClause];
Review Comment:
newer Java means can be one line
##########
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:
"changed"
This is an optimization; I would use wording reflective of this. If
theoretically it _was_ fast and then became slow for a short period, we could
say this is a regression. But it's been so long that I don't think we can
think of this as a regression in terms of category here and telling users about
it. The title could add more info the affected versions that were slower.
Title is a misnomer... you can use a few sentences if you wish.
##########
solr/core/src/java/org/apache/solr/search/LazyStringValue.java:
##########
@@ -0,0 +1,41 @@
+/*
+ * 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.search;
+
+import java.io.IOException;
+import org.apache.lucene.index.SortedDocValues;
+import org.apache.lucene.util.BytesRef;
+
+final class LazyStringValue {
+
+ final SortedDocValues dv;
+ final int ord;
+ final int missingOrd;
+
+ LazyStringValue(SortedDocValues dv, int ord, int missingOrd) {
+ this.dv = dv;
+ this.ord = ord;
+ this.missingOrd = missingOrd;
+ }
+
+ BytesRef materialize() throws IOException {
+ if (ord == missingOrd || ord < 0) {
+ return null;
+ }
+ return BytesRef.deepCopyOf(dv.lookupOrd(ord));
Review Comment:
IMO the deepCopy should be a decision by the caller... and we add a line of
javadocs to say the caller shouldn't hold a reference to it.
Well there's only one caller so... okay. Still; a bit of javadoc and
calling this method materializeCopy would be better.
##########
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:
Don't use SolrQuery & client.query for anything other than search. Here use
LukeRequest.
--
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]