You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by ge...@apache.org on 2023/03/06 18:44:26 UTC

[solr] branch branch_9x updated: SOLR-16680: Add JMH benchmark for Solr startup (#1377)

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

gerlowskija 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 79a536e146e SOLR-16680: Add JMH benchmark for Solr startup (#1377)
79a536e146e is described below

commit 79a536e146ee0a114c98d69d27673dfb0d1dbbc2
Author: Jason Gerlowski <ge...@apache.org>
AuthorDate: Wed Mar 1 10:40:13 2023 -0500

    SOLR-16680: Add JMH benchmark for Solr startup (#1377)
    
    
    Co-authored-by: Kevin Risden <ri...@users.noreply.github.com>
---
 .../apache/solr/bench/lifecycle/SolrStartup.java   | 120 +++++++++++++++++++++
 .../apache/solr/bench/lifecycle/package-info.java  |  19 ++++
 .../src/resources/configs/minimal/conf/schema.xml  |  21 ++++
 .../resources/configs/minimal/conf/solrconfig.xml  |  47 ++++++++
 solr/benchmark/src/resources/solr.xml              |  50 +++++++++
 5 files changed, 257 insertions(+)

diff --git a/solr/benchmark/src/java/org/apache/solr/bench/lifecycle/SolrStartup.java b/solr/benchmark/src/java/org/apache/solr/bench/lifecycle/SolrStartup.java
new file mode 100644
index 00000000000..6924d3d604d
--- /dev/null
+++ b/solr/benchmark/src/java/org/apache/solr/bench/lifecycle/SolrStartup.java
@@ -0,0 +1,120 @@
+/*
+ * 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.lifecycle;
+
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.concurrent.TimeUnit;
+import org.apache.commons.io.file.PathUtils;
+import org.apache.lucene.util.IOUtils;
+import org.apache.solr.client.solrj.SolrClient;
+import org.apache.solr.client.solrj.request.CoreAdminRequest;
+import org.apache.solr.client.solrj.response.CoreAdminResponse;
+import org.apache.solr.embedded.JettyConfig;
+import org.apache.solr.embedded.JettySolrRunner;
+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.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;
+
+/**
+ * A simple JMH benchmark that attempts to measure approximate Solr startup behavior by measuring
+ * {@link JettySolrRunner#start()}
+ */
+@BenchmarkMode(Mode.Throughput)
+@OutputTimeUnit(TimeUnit.SECONDS)
+@Measurement(time = 60, iterations = 10)
+@Threads(3)
+@Fork(value = 1)
+public class SolrStartup {
+
+  @Benchmark
+  public void startSolr(PerThreadState threadState) throws Exception {
+    // 'false' tells Jetty to not go out of its way to reuse any previous ports
+    threadState.solrRunner.start(false);
+  }
+
+  @State(Scope.Thread)
+  public static class PerThreadState {
+
+    private static final int NUM_CORES = 10;
+
+    public Path tmpSolrHome;
+    public JettySolrRunner solrRunner;
+
+    @Setup(Level.Trial)
+    public void bootstrapJettyServer() throws Exception {
+      tmpSolrHome = Files.createTempDirectory("solrstartup-perthreadstate-jsr").toAbsolutePath();
+
+      final Path configsetsDir = tmpSolrHome.resolve("configsets");
+      final Path defaultConfigsetDir = configsetsDir.resolve("defaultConfigSet");
+      Files.createDirectories(defaultConfigsetDir);
+      PathUtils.copyDirectory(
+          Path.of("src/resources/configs/minimal/conf"), defaultConfigsetDir.resolve("conf"));
+      PathUtils.copyFileToDirectory(Path.of("src/resources/solr.xml"), tmpSolrHome);
+
+      solrRunner = new JettySolrRunner(tmpSolrHome.toString(), buildJettyConfig("/solr"));
+      solrRunner.start(false);
+      try (SolrClient client = solrRunner.newClient()) {
+        for (int i = 0; i < NUM_CORES; i++) {
+          createCore(client, "core-prefix-" + i);
+        }
+      }
+      solrRunner.stop();
+    }
+
+    private void createCore(SolrClient client, String coreName) throws Exception {
+      CoreAdminRequest.Create create = new CoreAdminRequest.Create();
+      create.setCoreName(coreName);
+      create.setConfigSet("defaultConfigSet");
+
+      final CoreAdminResponse response = create.process(client);
+      if (response.getStatus() != 0) {
+        throw new RuntimeException("Some error creating core: " + response.jsonStr());
+      }
+    }
+
+    @TearDown(Level.Invocation)
+    public void stopJettyServerIfNecessary() throws Exception {
+      if (solrRunner.isRunning()) {
+        solrRunner.stop();
+      }
+    }
+
+    @TearDown(Level.Trial)
+    public void destroyJettyServer() throws Exception {
+      if (solrRunner.isRunning()) {
+        solrRunner.stop();
+      }
+
+      IOUtils.rm(tmpSolrHome);
+    }
+
+    private static JettyConfig buildJettyConfig(String context) {
+      return JettyConfig.builder().setContext(context).stopAtShutdown(true).build();
+    }
+  }
+}
diff --git a/solr/benchmark/src/java/org/apache/solr/bench/lifecycle/package-info.java b/solr/benchmark/src/java/org/apache/solr/bench/lifecycle/package-info.java
new file mode 100644
index 00000000000..00d9314ce5c
--- /dev/null
+++ b/solr/benchmark/src/java/org/apache/solr/bench/lifecycle/package-info.java
@@ -0,0 +1,19 @@
+/*
+ * 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.
+ */
+
+/** Benchmarks for various resource lifecycle events (e.g. Solr startup, collection creation) */
+package org.apache.solr.bench.lifecycle;
diff --git a/solr/benchmark/src/resources/configs/minimal/conf/schema.xml b/solr/benchmark/src/resources/configs/minimal/conf/schema.xml
new file mode 100644
index 00000000000..287d4fe0149
--- /dev/null
+++ b/solr/benchmark/src/resources/configs/minimal/conf/schema.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+ 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.
+-->
+<schema name="minimal" version="1.1">
+  <fieldType name="string" class="solr.StrField"/>
+  <dynamicField name="*" type="string" indexed="true" stored="true"/>
+</schema>
diff --git a/solr/benchmark/src/resources/configs/minimal/conf/solrconfig.xml b/solr/benchmark/src/resources/configs/minimal/conf/solrconfig.xml
new file mode 100644
index 00000000000..346b0448318
--- /dev/null
+++ b/solr/benchmark/src/resources/configs/minimal/conf/solrconfig.xml
@@ -0,0 +1,47 @@
+<?xml version="1.0" ?>
+
+<!--
+ 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.
+-->
+
+<!-- Minimal solrconfig.xml with /select, /admin and /update only -->
+
+<config>
+
+  <dataDir>${solr.data.dir:}</dataDir>
+
+  <directoryFactory name="DirectoryFactory"
+                    class="${solr.directoryFactory:solr.NRTCachingDirectoryFactory}"/>
+  <schemaFactory class="ClassicIndexSchemaFactory"/>
+
+  <luceneMatchVersion>${tests.luceneMatchVersion:LATEST}</luceneMatchVersion>
+
+  <updateHandler class="solr.DirectUpdateHandler2">
+    <commitWithin>
+      <softCommit>${solr.commitwithin.softcommit:true}</softCommit>
+    </commitWithin>
+
+  </updateHandler>
+  <requestHandler name="/select" class="solr.SearchHandler">
+    <lst name="defaults">
+      <str name="echoParams">explicit</str>
+      <str name="indent">true</str>
+      <str name="df">text</str>
+    </lst>
+
+  </requestHandler>
+</config>
+
diff --git a/solr/benchmark/src/resources/solr.xml b/solr/benchmark/src/resources/solr.xml
new file mode 100644
index 00000000000..439c8defdba
--- /dev/null
+++ b/solr/benchmark/src/resources/solr.xml
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+ 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.
+-->
+
+<!--
+ All (relative) paths are relative to the installation path
+-->
+<solr>
+
+  <metrics enabled="${metricsEnabled:true}"/>
+
+  <str name="shareSchema">${shareSchema:false}</str>
+  <str name="configSetBaseDir">${configSetBaseDir:configsets}</str>
+  <str name="coreRootDirectory">${coreRootDirectory:.}</str>
+  <str name="allowPaths">${solr.allowPaths:}</str>
+  <str name="allowUrls">${solr.tests.allowUrls:}</str>
+
+  <shardHandlerFactory name="shardHandlerFactory" class="HttpShardHandlerFactory">
+    <str name="urlScheme">${urlScheme:}</str>
+    <int name="socketTimeout">${socketTimeout:15000}</int>
+    <int name="connTimeout">${connTimeout:15000}</int>
+  </shardHandlerFactory>
+
+  <solrcloud>
+    <str name="host">127.0.0.1</str>
+    <int name="hostPort">${hostPort:8983}</int>
+    <str name="hostContext">${hostContext:solr}</str>
+    <int name="zkClientTimeout">${solr.zkclienttimeout:60000}</int> <!-- This should be high by default - dc's are expensive -->
+    <bool name="genericCoreNodeNames">${genericCoreNodeNames:true}</bool>
+    <int name="leaderVoteWait">${leaderVoteWait:15000}</int>   <!-- We are running tests - the default should be low, not like production -->
+    <int name="leaderConflictResolveWait">${leaderConflictResolveWait:45000}</int> 
+    <int name="distribUpdateConnTimeout">${distribUpdateConnTimeout:5000}</int>
+    <int name="distribUpdateSoTimeout">${distribUpdateSoTimeout:30000}</int> <!-- We are running tests - the default should be low, not like production -->
+  </solrcloud>
+  
+</solr>