Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

No Jira: Solr benchmark cleanup (#1987)

Alex D0deb354804f4
diff --git a/solr/benchmark/src/java/org/apache/solr/bench/BaseBenchState.java b/solr/benchmark/src/java/org/apache/solr/bench/BaseBenchState.java
index 4db40c05112..e3b5012366b 100644
--- a/solr/benchmark/src/java/org/apache/solr/bench/BaseBenchState.java
+++ b/solr/benchmark/src/java/org/apache/solr/bench/BaseBenchState.java
@@ -41,11 +41,9 @@ import org.slf4j.LoggerFactory;
@State(Scope.Benchmark)
public class BaseBenchState {
- private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+ private static final long RANDOM_SEED = System.nanoTime();
- private static final long RANDOM_SEED = 6624420638116043983L;
-
- private static final SplittableRandom random = new SplittableRandom(getInitRandomeSeed());
+ private static final SplittableRandom random = new SplittableRandom(getInitRandomSeed());
/**
* Gets random seed.
@@ -137,13 +135,14 @@ public class BaseBenchState {
}
}
- private static Long getInitRandomeSeed() {
+ private static Long getInitRandomSeed() {
Long seed = Long.getLong("solr.bench.seed");
if (seed == null) {
seed = RANDOM_SEED;
}
+ log("");
log("benchmark random seed: " + seed);
return seed;
diff --git a/solr/benchmark/src/java/org/apache/solr/bench/CircularIterator.java b/solr/benchmark/src/java/org/apache/solr/bench/CircularIterator.java
new file mode 100644
index 00000000000..529d5812442
--- /dev/null
+++ b/solr/benchmark/src/java/org/apache/solr/bench/CircularIterator.java
@@ -0,0 +1,51 @@
+/*
+ * 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 java.util.Collection;
+import java.util.Iterator;
+import java.util.Objects;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class CircularIterator<T> implements Iterator<T> {
+
+ private final Object[] collection;
+ private final AtomicInteger idx;
+
+ public CircularIterator(Collection<T> collection) {
+ this.collection = Objects.requireNonNull(collection).toArray();
+ if (this.collection.length == 0) {
+ throw new IllegalArgumentException("This iterator doesn't support empty collections");
+ }
+ this.idx = new AtomicInteger();
+ }
+
+ @Override
+ public boolean hasNext() {
+ return true;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public T next() {
+ return (T) collection[idx.incrementAndGet() % collection.length];
+ }
+
+ public int cycles() {
+ return ((idx.get() - 1) / collection.length) + 1;
+ }
+}
diff --git a/solr/benchmark/src/java/org/apache/solr/bench/Docs.java b/solr/benchmark/src/java/org/apache/solr/bench/Docs.java
index cfaca270571..5c3b889c7a6 100644
--- a/solr/benchmark/src/java/org/apache/solr/bench/Docs.java
+++ b/solr/benchmark/src/java/org/apache/solr/bench/Docs.java
@@ -18,7 +18,6 @@ package org.apache.solr.bench;
import static org.apache.solr.bench.BaseBenchState.log;
-import java.lang.invoke.MethodHandles;
import java.util.Collections;
import java.util.Date;
import java.util.Iterator;
@@ -38,8 +37,6 @@ import org.apache.solr.common.util.SolrNamedThreadFactory;
import org.apache.solr.common.util.SuppressForbidden;
import org.quicktheories.core.Gen;
import org.quicktheories.impl.BenchmarkRandomSource;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
* A tool to generate controlled random data for a benchmark. {@link SolrInputDocument}s are created
@@ -50,8 +47,6 @@ import org.slf4j.LoggerFactory;
* them via {@link #generatedDocsIterator}.
*/
public class Docs {
- private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
-
private final ThreadLocal<SolrRandomnessSource> random;
private final Queue<SolrInputDocument> docs = new ConcurrentLinkedQueue<>();
@@ -104,7 +99,7 @@ public class Docs {
*/
@SuppressForbidden(reason = "This module does not need to deal with logging context")
public Iterator<SolrInputDocument> preGenerate(int numDocs) throws InterruptedException {
- log("preGenerate docs " + numDocs + " ...");
+ log("preGenerate docs=" + numDocs + " ...");
docs.clear();
executorService =
Executors.newFixedThreadPool(
@@ -114,14 +109,7 @@ public class Docs {
for (int i = 0; i < numDocs; i++) {
executorService.submit(
() -> {
- try {
- SolrInputDocument doc = Docs.this.inputDocument();
- docs.add(doc);
- } catch (Exception e) {
- log.error("error adding doc", e);
- executorService.shutdownNow();
- throw new RuntimeException(e);
- }
+ docs.add(Docs.this.inputDocument());
});
}
@@ -144,7 +132,7 @@ public class Docs {
}
/**
- * Generated docs iterator iterator.
+ * Generated docs iterator.
*
* @return the iterator
*/
@@ -152,6 +140,15 @@ public class Docs {
return docs.iterator();
}
+ /**
+ * Generated docs circular iterator.
+ *
+ * @return the iterator that never ends
+ */
+ public CircularIterator<SolrInputDocument> generatedDocsCircularIterator() {
+ return new CircularIterator<>(docs);
+ }
+
/**
* Input document solr input document.
*
diff --git a/solr/benchmark/src/java/org/apache/solr/bench/MiniClusterState.java b/solr/benchmark/src/java/org/apache/solr/bench/MiniClusterState.java
index dd1c0afe639..5a793448c5c 100755
--- a/solr/benchmark/src/java/org/apache/solr/bench/MiniClusterState.java
+++ b/solr/benchmark/src/java/org/apache/solr/bench/MiniClusterState.java
@@ -24,7 +24,6 @@ import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
-import java.lang.invoke.MethodHandles;
import java.lang.management.ManagementFactory;
import java.net.URL;
import java.nio.charset.StandardCharsets;
@@ -61,21 +60,14 @@ import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.TearDown;
import org.openjdk.jmh.infra.BenchmarkParams;
import org.openjdk.jmh.infra.Control;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/** The base class for Solr JMH benchmarks that operate against a {@code MiniSolrCloudCluster}. */
public class MiniClusterState {
- /** The constant DEBUG_OUTPUT. */
- public static final boolean DEBUG_OUTPUT = false;
-
/** The constant PROC_COUNT. */
public static final int PROC_COUNT =
ManagementFactory.getOperatingSystemMXBean().getAvailableProcessors();
- private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
-
/** The type Mini cluster bench state. */
@State(Scope.Benchmark)
public static class MiniClusterBenchState {
@@ -118,7 +110,7 @@ public class MiniClusterState {
private SplittableRandom random;
private String workDir;
- private boolean useHttp1 = false;
+ private boolean useHttp1 = Boolean.getBoolean("solr.http1");
/**
* Tear down.
@@ -163,14 +155,30 @@ public class MiniClusterState {
@TearDown(Level.Trial)
public void shutdownMiniCluster(BenchmarkParams benchmarkParams, BaseBenchState baseBenchState)
throws Exception {
-
- log.info("MiniClusterState tear down - baseBenchState is {}", baseBenchState);
-
BaseBenchState.dumpHeap(benchmarkParams);
- if (DEBUG_OUTPUT) log("closing client and shutting down minicluster");
IOUtils.closeQuietly(client);
cluster.shutdown();
+ logClusterDirectorySize();
+ }
+
+ private void logClusterDirectorySize() throws IOException {
+ log("");
+ Files.list(miniClusterBaseDir.toAbsolutePath())
+ .forEach(
+ (node) -> {
+ try {
+ long clusterSize =
+ Files.walk(node)
+ .filter(Files::isRegularFile)
+ .map(Path::toFile)
+ .mapToLong(File::length)
+ .sum();
+ log("mini cluster node size (bytes) " + node + " " + clusterSize);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ });
}
/**
@@ -191,7 +199,6 @@ public class MiniClusterState {
workDir = System.getProperty("workBaseDir", "build/work");
- log("");
Path currentRelativePath = Paths.get("");
String s = currentRelativePath.toAbsolutePath().toString();
log("current relative path is: " + s);
@@ -373,9 +380,7 @@ public class MiniClusterState {
queryRequest.setBasePath(nodes.get(random.nextInt(cluster.getJettySolrRunners().size())));
NamedList<Object> result = client.request(queryRequest, collection);
-
- if (DEBUG_OUTPUT) log("result: " + result);
-
+ log("sanity check of single row query result: " + result);
log("");
log("Dump Core Info");
@@ -443,7 +448,7 @@ public class MiniClusterState {
throws SolrServerException, IOException {
Meter meter = new Meter();
List<SolrInputDocument> batch = new ArrayList<>(batchSize);
- for (int i = 0; i < docCount; i++) {
+ for (int i = 1; i <= docCount; i++) {
batch.add(docs.inputDocument());
if (i % batchSize == 0) {
UpdateRequest updateRequest = new UpdateRequest();
@@ -452,7 +457,7 @@ public class MiniClusterState {
client.request(updateRequest, collection);
meter.mark(batch.size());
batch.clear();
- log(meter.getCount() + " docs at " + meter.getMeanRate() + " doc/s");
+ log(meter.getCount() + " docs at " + (long) meter.getMeanRate() + " doc/s");
}
}
if (!batch.isEmpty()) {
@@ -463,7 +468,7 @@ public class MiniClusterState {
meter.mark(batch.size());
batch = null;
}
- log(meter.getCount() + " docs at " + meter.getMeanRate() + " doc/s");
+ log(meter.getCount() + " docs at " + (long) meter.getMeanRate() + " doc/s");
}
/**
diff --git a/solr/benchmark/src/java/org/apache/solr/bench/index/CloudIndexing.java b/solr/benchmark/src/java/org/apache/solr/bench/index/CloudIndexing.java
index 981ce0dc455..820f2130a60 100755
--- a/solr/benchmark/src/java/org/apache/solr/bench/index/CloudIndexing.java
+++ b/solr/benchmark/src/java/org/apache/solr/bench/index/CloudIndexing.java
@@ -23,6 +23,7 @@ import static org.apache.solr.bench.generators.SourceDSL.strings;
import java.util.Iterator;
import java.util.concurrent.TimeUnit;
+import org.apache.solr.bench.Docs;
import org.apache.solr.bench.MiniClusterState;
import org.apache.solr.client.solrj.request.UpdateRequest;
import org.apache.solr.common.SolrInputDocument;
@@ -37,19 +38,15 @@ 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.Timeout;
import org.openjdk.jmh.annotations.Warmup;
-import org.openjdk.jmh.infra.BenchmarkParams;
@BenchmarkMode(Mode.Throughput)
@OutputTimeUnit(TimeUnit.SECONDS)
-@Threads(4)
-@Warmup(time = 10, iterations = 3)
-@Measurement(time = 20, iterations = 4)
+@Threads(16)
+@Warmup(time = 15, iterations = 2)
+@Measurement(time = 60, iterations = 4)
@Fork(value = 1)
-@Timeout(time = 60)
// A benchmark to experiment with the performance of distributed indexing.
public class CloudIndexing {
@@ -58,32 +55,26 @@ public class CloudIndexing {
static final String COLLECTION = "testCollection";
- @Param({"1"})
- public int scale;
-
@Param("4")
int nodeCount;
- @Param("5")
+ @Param("4")
int numShards;
@Param({"1", "3"})
int numReplicas;
- @Param({"0", "15", "30", "70", "100", "500", "1000"})
- int useStringUtf8Over;
-
@Param({"true", "false"})
- boolean directBuffer;
+ boolean useSmallDocs;
- private final org.apache.solr.bench.Docs largeDocs;
- private Iterator<SolrInputDocument> largeDocIterator;
+ @Param({"50000"})
+ int preGenerate;
- private final org.apache.solr.bench.Docs smallDocs;
- private Iterator<SolrInputDocument> smallDocIterator;
+ private final Docs largeDocs;
+ private final Docs smallDocs;
+ private Iterator<SolrInputDocument> docIterator;
public BenchState() {
-
largeDocs =
docs()
.field("id", integers().incrementing())
@@ -94,81 +85,51 @@ public class CloudIndexing {
.field(integers().all())
.field(longs().all())
.field(longs().all());
+ smallDocs =
+ docs()
+ .field("id", integers().incrementing())
+ .field("text", strings().basicLatinAlphabet().multi(2).ofLengthBetween(20, 32))
+ .field("int1_i", integers().all())
+ .field("int2_i", integers().all())
+ .field("long1_l", longs().all());
+ }
- try {
- largeDocIterator = largeDocs.preGenerate(50000);
-
- smallDocs =
- docs()
- .field("id", integers().incrementing())
- .field("text", strings().basicLatinAlphabet().multi(2).ofLengthBetween(20, 32))
- .field("int1_i", integers().all())
- .field("int2_i", integers().all())
- .field("long1_l", longs().all());
+ private SolrInputDocument getNextDoc() {
+ return docIterator.next();
+ }
- smallDocIterator = smallDocs.preGenerate(50000);
+ private void preGenerate() {
+ try {
+ if (useSmallDocs) {
+ smallDocs.preGenerate(preGenerate);
+ docIterator = smallDocs.generatedDocsCircularIterator();
+ } else {
+ largeDocs.preGenerate(preGenerate);
+ docIterator = largeDocs.generatedDocsCircularIterator();
+ }
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new RuntimeException(e);
}
}
- public SolrInputDocument getLargeDoc() {
- if (!largeDocIterator.hasNext()) {
- largeDocIterator = largeDocs.generatedDocsIterator();
- }
- return largeDocIterator.next();
- }
-
- public SolrInputDocument getSmallDoc() {
- if (!smallDocIterator.hasNext()) {
- smallDocIterator = smallDocs.generatedDocsIterator();
- }
- return smallDocIterator.next();
- }
-
@Setup(Level.Trial)
public void doSetup(MiniClusterState.MiniClusterBenchState miniClusterState) throws Exception {
- System.setProperty("useStringUtf8Over", Integer.toString(useStringUtf8Over));
- System.setProperty("httpClientDirectBuffer", Boolean.toString(directBuffer));
+ preGenerate();
System.setProperty("mergePolicyFactory", "org.apache.solr.index.NoMergePolicyFactory");
miniClusterState.startMiniCluster(nodeCount);
miniClusterState.createCollection(COLLECTION, numShards, numReplicas);
}
-
- @TearDown(Level.Trial)
- public void doTearDown(
- MiniClusterState.MiniClusterBenchState miniClusterState, BenchmarkParams benchmarkParams)
- throws Exception {
-
- // miniClusterState.shutdownMiniCluster(benchmarkParams);
- }
- }
-
- @Benchmark
- @Timeout(time = 300)
- public Object indexLargeDoc(
- MiniClusterState.MiniClusterBenchState miniClusterState, BenchState state) throws Exception {
- UpdateRequest updateRequest = new UpdateRequest();
- updateRequest.setBasePath(
- miniClusterState.nodes.get(miniClusterState.getRandom().nextInt(state.nodeCount)));
- SolrInputDocument doc = state.getLargeDoc();
- updateRequest.add(doc);
-
- return miniClusterState.client.request(updateRequest, BenchState.COLLECTION);
}
@Benchmark
- @Timeout(time = 300)
- public Object indexSmallDoc(
- MiniClusterState.MiniClusterBenchState miniClusterState, BenchState state) throws Exception {
+ public Object indexDoc(MiniClusterState.MiniClusterBenchState miniClusterState, BenchState state)
+ throws Exception {
UpdateRequest updateRequest = new UpdateRequest();
updateRequest.setBasePath(
miniClusterState.nodes.get(miniClusterState.getRandom().nextInt(state.nodeCount)));
- SolrInputDocument doc = state.getSmallDoc();
- updateRequest.add(doc);
-
+ updateRequest.add(state.getNextDoc());
return miniClusterState.client.request(updateRequest, BenchState.COLLECTION);
}
}
diff --git a/solr/benchmark/src/java/org/apache/solr/bench/search/NumericSearch.java b/solr/benchmark/src/java/org/apache/solr/bench/search/NumericSearch.java
index a96a714ebef..3c7a72385f9 100644
--- a/solr/benchmark/src/java/org/apache/solr/bench/search/NumericSearch.java
+++ b/solr/benchmark/src/java/org/apache/solr/bench/search/NumericSearch.java
@@ -21,13 +21,11 @@ import static org.apache.solr.bench.generators.SourceDSL.integers;
import static org.apache.solr.bench.generators.SourceDSL.strings;
import java.io.IOException;
-import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
-import java.util.Objects;
import java.util.Set;
-import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
+import org.apache.solr.bench.CircularIterator;
import org.apache.solr.bench.Docs;
import org.apache.solr.bench.MiniClusterState;
import org.apache.solr.bench.generators.SolrGen;
@@ -177,31 +175,6 @@ public class NumericSearch {
q.setBasePath(basePath);
return q;
}
-
- private static class CircularIterator<T> implements Iterator<T> {
-
- private final Object[] collection;
- private final AtomicInteger idx;
-
- CircularIterator(Collection<T> collection) {
- this.collection = Objects.requireNonNull(collection).toArray();
- if (this.collection.length == 0) {
- throw new IllegalArgumentException("This iterator doesn't support empty collections");
- }
- this.idx = new AtomicInteger();
- }
-
- @Override
- public boolean hasNext() {
- return true;
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public T next() {
- return (T) collection[idx.incrementAndGet() % collection.length];
- }
- }
}
@Benchmark