markrmiller commented on a change in pull request #214:
URL: https://github.com/apache/solr/pull/214#discussion_r683080952



##########
File path: solr/benchmark/src/java/org/apache/solr/bench/MiniClusterState.java
##########
@@ -0,0 +1,370 @@
+/*
+ * 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;
+
+import static org.apache.commons.io.file.PathUtils.deleteDirectory;
+
+import com.codahale.metrics.Meter;
+import java.io.IOException;
+import java.lang.management.ManagementFactory;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Random;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+import org.apache.commons.io.output.NullPrintStream;
+import org.apache.solr.client.solrj.SolrClient;
+import org.apache.solr.client.solrj.SolrQuery;
+import org.apache.solr.client.solrj.embedded.JettySolrRunner;
+import org.apache.solr.client.solrj.impl.Http2SolrClient;
+import org.apache.solr.client.solrj.request.CollectionAdminRequest;
+import org.apache.solr.client.solrj.request.QueryRequest;
+import org.apache.solr.client.solrj.request.UpdateRequest;
+import org.apache.solr.cloud.MiniSolrCloudCluster;
+import org.apache.solr.common.SolrInputDocument;
+import org.apache.solr.common.params.ModifiableSolrParams;
+import org.apache.solr.common.util.IOUtils;
+import org.apache.solr.common.util.NamedList;
+import org.apache.solr.common.util.SolrNamedThreadFactory;
+import org.apache.solr.common.util.SuppressForbidden;
+import org.openjdk.jmh.annotations.Level;
+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.infra.BenchmarkParams;
+import org.openjdk.jmh.infra.Control;
+
+/** The base class for Solr JMH benchmarks that operate against a {@link 
MiniSolrCloudCluster}. */
+public class MiniClusterState {
+
+  public static final boolean DEBUG_OUTPUT = false;
+
+  public static final int PROC_COUNT =
+      ManagementFactory.getOperatingSystemMXBean().getAvailableProcessors();
+
+  private static boolean quietLog = Boolean.getBoolean("quietLog");
+
+  @SuppressForbidden(reason = "JMH uses std out for user output")
+  public static void log(String value) {
+    if (!quietLog) {
+      System.out.println((value.equals("") ? "" : "--> ") + value);
+    }
+  }
+
+  @State(Scope.Benchmark)
+  public static class MiniClusterBenchState {
+
+    boolean metricsEnabled = true;
+
+    public List<String> nodes;
+    MiniSolrCloudCluster cluster;
+    public SolrClient client;
+
+    int runCnt = 0;
+
+    boolean createCollectionAndIndex = true;
+
+    boolean deleteMiniCluster = true;
+
+    Path baseDir;
+    boolean allowClusterReuse = false;
+
+    ThreadPoolExecutor exec;
+
+    boolean isWarmup;
+
+    @TearDown(Level.Iteration)
+    public void tearDown(BenchmarkParams benchmarkParams) throws Exception {
+
+      // dump Solr metrics
+      Path metricsResults =
+          Paths.get(
+              "work/metrics-results",
+              benchmarkParams.id(),
+              String.valueOf(runCnt++),
+              benchmarkParams.getBenchmark() + ".txt");
+      if (!Files.exists(metricsResults.getParent())) {
+        Files.createDirectories(metricsResults.getParent());
+      }
+
+      cluster.outputMetrics(
+          metricsResults.getParent().toFile(), 
metricsResults.getFileName().toString());
+    }
+
+    @Setup(Level.Iteration)
+    public void checkWarmUp(Control control) throws Exception {
+      isWarmup = control.stopMeasurement;
+    }
+
+    @TearDown(Level.Trial)
+    public void shutdownMiniCluster() throws Exception {
+      if (DEBUG_OUTPUT) log("closing client and shutting down minicluster");
+      IOUtils.closeQuietly(client);
+      cluster.shutdown();
+    }
+
+    @Setup(Level.Trial)
+    public void doSetup(BenchmarkParams benchmarkParams) throws Exception {
+
+      MiniClusterState.log("");
+      Path currentRelativePath = Paths.get("");
+      String s = currentRelativePath.toAbsolutePath().toString();
+      log("current relative path is: " + s);
+
+      Long seed = Long.getLong("solr.bench.seed");
+
+      if (seed == null) {
+        seed = ThreadLocalRandom.current().nextLong();
+      }
+
+      // set the seed used by ThreadLocalRandom
+      System.setProperty("randomSeed", Long.toString(new 
Random(seed).nextLong()));

Review comment:
       @sonatype-lift ignore




-- 
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: issues-unsubscr...@solr.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org
For additional commands, e-mail: issues-h...@solr.apache.org

Reply via email to