You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by tf...@apache.org on 2023/06/23 22:15:33 UTC

[solr] branch branch_9x updated: SOLR-16841 QueryResponseWriter benchmarks (#1705)

This is an automated email from the ASF dual-hosted git repository.

tflobbe pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/solr.git


The following commit(s) were added to refs/heads/branch_9x by this push:
     new 8ce55513426 SOLR-16841 QueryResponseWriter benchmarks (#1705)
8ce55513426 is described below

commit 8ce555134267c8bbf7339dcbe0c6f738dcad655e
Author: Alex <st...@apache.org>
AuthorDate: Fri Jun 23 15:14:21 2023 -0700

    SOLR-16841 QueryResponseWriter benchmarks (#1705)
    
    
    ---------
    
    Co-authored-by: Tomas Fernandez Lobbe <tf...@apache.org>
---
 solr/CHANGES.txt                                   |   2 +
 solr/benchmark/log4j2-bench.xml                    |  12 +--
 .../solr/bench/search/QueryResponseWriters.java    | 111 +++++++++++++++++++++
 .../configs/cloud-minimal/conf/schema.xml          |   2 +
 .../solr/client/solrj/impl/NoOpResponseParser.java |   2 +-
 5 files changed, 122 insertions(+), 7 deletions(-)

diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index f754781b5a4..41135f400e7 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -245,6 +245,8 @@ Other Changes
 
 * PR#1566: Removed deprecated members from Tuple class (janhoy)
 
+* SOLR-16841: Added QueryResponseWriter benchmarks (Alex Deparvu via Tomás Fernández Löbbe)
+
 ==================  9.2.1 ==================
 
 Bug Fixes
diff --git a/solr/benchmark/log4j2-bench.xml b/solr/benchmark/log4j2-bench.xml
index 29db12fc23b..eb961d4dc0e 100644
--- a/solr/benchmark/log4j2-bench.xml
+++ b/solr/benchmark/log4j2-bench.xml
@@ -31,8 +31,8 @@
 
     <RollingRandomAccessFile
         name="MainLogFile"
-        fileName="${sys:solr.log.dir:-work/solr-logs}/${sys:solr.log.name:-solr}.log"
-        filePattern="${sys:solr.log.dir:-work/solr-logs}/${sys:solr.log.name:-solr}.log.%i">
+        fileName="${sys:solr.log.dir:-build/work/solr-logs}/${sys:solr.log.name:-solr}.log"
+        filePattern="${sys:solr.log.dir:-build/work/solr-logs}/${sys:solr.log.name:-solr}.log.%i">
       <PatternLayout>
         <Pattern>
           %maxLen{%d{yyyy-MM-dd HH:mm:ss.SSS} %-5p (%t) [%notEmpty{c:%X{collection}}%notEmpty{ s:%X{shard}}%notEmpty{ r:%X{replica}}%notEmpty{ x:%X{core}}] %c{1.}
@@ -48,8 +48,8 @@
 
     <RollingRandomAccessFile
         name="SlowLogFile"
-        fileName="${sys:solr.log.dir:-work/solr-logs}/${sys:solr.log.name:-solr}_slow_requests.log"
-        filePattern="${sys:solr.log.dir:-work/solr-logs}/${sys:solr.log.name:-solr}_slow_requests.log.%i">
+        fileName="${sys:solr.log.dir:-build/work/solr-logs}/${sys:solr.log.name:-solr}_slow_requests.log"
+        filePattern="${sys:solr.log.dir:-build/work/solr-logs}/${sys:solr.log.name:-solr}_slow_requests.log.%i">
       <PatternLayout>
         <Pattern>
           %maxLen{%d{yyyy-MM-dd HH:mm:ss.SSS} %-5p (%t) [%notEmpty{c:%X{collection}}%notEmpty{ s:%X{shard}}%notEmpty{ r:%X{replica}}%notEmpty{ x:%X{core}}] %c{1.}
@@ -66,8 +66,8 @@
 
     <RollingRandomAccessFile
         name="RandomCountsFile"
-        fileName="${sys:solr.log.dir:-work/solr-logs}/${sys:solr.log.name:-solr}_random_counts.log"
-        filePattern="${sys:solr.log.dir:-work/solr-logs}/${sys:solr.log.name:-solr}_random_counts.log.%i">
+        fileName="${sys:solr.log.dir:-build/work/solr-logs}/${sys:solr.log.name:-solr}_random_counts.log"
+        filePattern="${sys:solr.log.dir:-build/work/solr-logs}/${sys:solr.log.name:-solr}_random_counts.log.%i">
       <PatternLayout>
         <Pattern>
           %maxLen{%d{yyyy-MM-dd HH:mm:ss.SSS} %-5p (%t) [%notEmpty{c:%X{collection}}%notEmpty{ s:%X{shard}}%notEmpty{ r:%X{replica}}%notEmpty{ x:%X{core}}] %c{1.}
diff --git a/solr/benchmark/src/java/org/apache/solr/bench/search/QueryResponseWriters.java b/solr/benchmark/src/java/org/apache/solr/bench/search/QueryResponseWriters.java
new file mode 100644
index 00000000000..15b4526d49e
--- /dev/null
+++ b/solr/benchmark/src/java/org/apache/solr/bench/search/QueryResponseWriters.java
@@ -0,0 +1,111 @@
+/*
+ * 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 static org.apache.solr.bench.Docs.docs;
+import static org.apache.solr.bench.generators.SourceDSL.booleans;
+import static org.apache.solr.bench.generators.SourceDSL.integers;
+import static org.apache.solr.bench.generators.SourceDSL.strings;
+
+import java.io.IOException;
+import org.apache.solr.bench.Docs;
+import org.apache.solr.bench.MiniClusterState;
+import org.apache.solr.bench.MiniClusterState.MiniClusterBenchState;
+import org.apache.solr.client.solrj.SolrServerException;
+import org.apache.solr.client.solrj.impl.NoOpResponseParser;
+import org.apache.solr.client.solrj.request.QueryRequest;
+import org.apache.solr.common.params.CommonParams;
+import org.apache.solr.common.params.ModifiableSolrParams;
+import org.apache.solr.core.SolrCore;
+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.Param;
+import org.openjdk.jmh.annotations.Scope;
+import org.openjdk.jmh.annotations.Setup;
+import org.openjdk.jmh.annotations.State;
+import org.openjdk.jmh.annotations.Threads;
+import org.openjdk.jmh.annotations.Warmup;
+
+@Fork(value = 1)
+@BenchmarkMode(Mode.Throughput)
+@Warmup(time = 5, iterations = 2)
+@Measurement(time = 30, iterations = 4)
+@Threads(value = 1)
+public class QueryResponseWriters {
+
+  // See also TestWriterPerf
+
+  private static final String collection = "benchQueryResponseWriters";
+
+  @State(Scope.Benchmark)
+  public static class BenchState {
+
+    /** See {@link SolrCore#DEFAULT_RESPONSE_WRITERS} */
+    @Param({
+      CommonParams.JAVABIN,
+      CommonParams.JSON,
+      "cbor",
+      "smile",
+      "xml",
+      "python",
+      "phps",
+      "ruby",
+      "raw"
+    })
+    String wt;
+
+    private int docs = 100;
+    private QueryRequest q;
+
+    @Setup(Level.Trial)
+    public void setup(MiniClusterBenchState miniClusterState) throws Exception {
+
+      miniClusterState.startMiniCluster(1);
+      miniClusterState.createCollection(collection, 1, 1);
+
+      // only stored fields are needed to cover the response writers perf
+      Docs docGen =
+          docs()
+              .field("id", integers().incrementing())
+              .field("text2_ts", strings().basicLatinAlphabet().multi(25).ofLengthBetween(30, 64))
+              .field("bools_b", booleans().all())
+              .field("int1_is", integers().all());
+      miniClusterState.index(collection, docGen, docs);
+      miniClusterState.forceMerge(collection, 5);
+
+      ModifiableSolrParams params = new ModifiableSolrParams();
+      params.set(CommonParams.Q, "*:*");
+      params.set(CommonParams.WT, wt);
+      params.set(CommonParams.ROWS, docs);
+      q = new QueryRequest(params);
+      q.setResponseParser(new NoOpResponseParser(wt));
+      String base = miniClusterState.nodes.get(0);
+      q.setBasePath(base);
+    }
+  }
+
+  @Benchmark
+  public Object query(
+      BenchState benchState, MiniClusterState.MiniClusterBenchState miniClusterState)
+      throws SolrServerException, IOException {
+    return miniClusterState.client.request(benchState.q, collection);
+  }
+}
diff --git a/solr/benchmark/src/resources/configs/cloud-minimal/conf/schema.xml b/solr/benchmark/src/resources/configs/cloud-minimal/conf/schema.xml
index d950c8db5db..cbdf1bac1f2 100644
--- a/solr/benchmark/src/resources/configs/cloud-minimal/conf/schema.xml
+++ b/solr/benchmark/src/resources/configs/cloud-minimal/conf/schema.xml
@@ -44,8 +44,10 @@
     <dynamicField name="*_b" type="boolean" indexed="true" stored="true"/>
     <dynamicField name="*_s" type="string" indexed="true" stored="false"/>
     <dynamicField name="*_t" type="text" indexed="true" stored="false"/>
+    <dynamicField name="*_ts" type="text" indexed="true" stored="true"/>
     <dynamicField name="*_i" type="int" indexed="true" stored="false"/>
     <dynamicField name="*_i_dv" type="int" indexed="true" docValues="true" stored="false"/>
+    <dynamicField name="*_is" type="int" indexed="false" stored="true"/>
     <dynamicField name="*_l" type="long" indexed="true" stored="false"/>
     <dynamicField name="*_l_dv" type="long" indexed="true" docValues="true" stored="false"/>
     <dynamicField name="*_f" type="float" indexed="true" stored="false"/>
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/NoOpResponseParser.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/NoOpResponseParser.java
index 516cf30eb5e..919b6b873f1 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/NoOpResponseParser.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/NoOpResponseParser.java
@@ -66,7 +66,7 @@ public class NoOpResponseParser extends ResponseParser {
   public NamedList<Object> processResponse(InputStream body, String encoding) {
     try {
       StringWriter writer = new StringWriter();
-      new InputStreamReader(body, encoding).transferTo(writer);
+      new InputStreamReader(body, encoding == null ? "UTF-8" : encoding).transferTo(writer);
       String output = writer.toString();
       NamedList<Object> list = new NamedList<>();
       list.add("response", output);