Skip to content

Commit

Permalink
GH-3857 copy benchmarks from develop branch to allow us to compare pe…
Browse files Browse the repository at this point in the history
…rformance accurately
  • Loading branch information
hmottestad committed May 23, 2022
1 parent af3afc9 commit f0eb270
Show file tree
Hide file tree
Showing 11 changed files with 475 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Scope;
Expand All @@ -22,11 +23,11 @@
@State(Scope.Benchmark)
public class BaseConcurrentBenchmark {

ExecutorService executorService;
private ExecutorService executorService;

@Setup(Level.Trial)
public void setup() throws Exception {
executorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
executorService = Executors.newFixedThreadPool(8);
}

@TearDown(Level.Trial)
Expand Down Expand Up @@ -57,6 +58,10 @@ void threads(int threadCount, Runnable runnable) throws InterruptedException {

}

Future<?> submit(Runnable runnable) {
return executorService.submit(runnable);
}

static InputStream getResourceAsStream(String filename) {
return BaseConcurrentBenchmark.class.getClassLoader().getResourceAsStream(filename);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/*******************************************************************************
* Copyright (c) 2022 Eclipse RDF4J contributors.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Distribution License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
******************************************************************************/

package org.eclipse.rdf4j.sail.memory.benchmark;

import java.io.InputStream;
import java.util.concurrent.TimeUnit;

import org.eclipse.rdf4j.common.transaction.IsolationLevels;
import org.eclipse.rdf4j.repository.sail.SailRepository;
import org.eclipse.rdf4j.repository.sail.SailRepositoryConnection;
import org.eclipse.rdf4j.rio.RDFFormat;
import org.eclipse.rdf4j.sail.memory.MemoryStore;
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.Warmup;
import org.openjdk.jmh.infra.Blackhole;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;

/**
* @author Håvard M. Ottestad
*/
@State(Scope.Benchmark)
@Warmup(iterations = 5)
@BenchmarkMode({ Mode.AverageTime })
@Fork(value = 1, jvmArgs = { "-Xms1G", "-Xmx1G", })
@Measurement(iterations = 5)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
public class ConcurrentQueryBenchmark extends BaseConcurrentBenchmark {

private SailRepository repository;

public static void main(String[] args) throws RunnerException {
Options opt = new OptionsBuilder()
.include("ConcurrentQueryBenchmark.*") // adapt to run other benchmark tests
.forks(1)
.build();

new Runner(opt).run();
}

@Setup(Level.Trial)
public void setup() throws Exception {
super.setup();
repository = new SailRepository(new MemoryStore());

try (SailRepositoryConnection connection = repository.getConnection()) {
connection.begin(IsolationLevels.NONE);
try (InputStream resourceAsStream = getResourceAsStream("benchmarkFiles/datagovbe-valid.ttl")) {
connection.add(resourceAsStream, RDFFormat.TURTLE);
}
connection.commit();

}

}

@TearDown(Level.Trial)
public void tearDown() throws Exception {
super.tearDown();
repository.shutDown();
}

@Benchmark
public void hasStatement(Blackhole blackhole) throws Exception {
threads(100, () -> {
try (SailRepositoryConnection connection = repository.getConnection()) {
for (int i = 0; i < 100; i++) {
boolean b = connection.hasStatement(null, null, null, true);
blackhole.consume(b);
}
}
});
}

@Benchmark
public void hasStatementSharedConnection(Blackhole blackhole) throws Exception {
try (SailRepositoryConnection connection = repository.getConnection()) {
threads(100, () -> {
for (int i = 0; i < 100; i++) {
boolean b = connection.hasStatement(null, null, null, true);
blackhole.consume(b);
}
});
}
}

@Benchmark
public void getNamespaces(Blackhole blackhole) throws Exception {
threads(100, () -> {
try (SailRepositoryConnection connection = repository.getConnection()) {
for (int i = 0; i < 100; i++) {
blackhole.consume(connection.getNamespaces().stream().count());
}
}
});
}

@Benchmark
public void getNamespacesSharedConnection(Blackhole blackhole) throws Exception {
try (SailRepositoryConnection connection = repository.getConnection()) {
threads(100, () -> {
for (int i = 0; i < 100; i++) {
blackhole.consume(connection.getNamespaces().stream().count());
}
});
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@
import org.openjdk.jmh.runner.options.OptionsBuilder;

@State(Scope.Benchmark)
@Warmup(iterations = 20)
@Warmup(iterations = 5)
@BenchmarkMode({ Mode.AverageTime })
//@Fork(value = 1, jvmArgs = {"-Xms4G", "-Xmx4G", "-XX:+UseSerialGC", "-XX:+UnlockCommercialFeatures", "-XX:StartFlightRecording=delay=5s,duration=60s,filename=recording.jfr,settings=profile", "-XX:FlightRecorderOptions=samplethreads=true,stackdepth=1024", "-XX:+UnlockDiagnosticVMOptions", "-XX:+DebugNonSafepoints"})
@Fork(value = 1, jvmArgs = { "-Xms4G", "-Xmx4G", "-XX:+UseSerialGC" })
@Measurement(iterations = 10)
@Measurement(iterations = 5)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
public class LoadingBenchmark {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@
* @author Håvard M. Ottestad
*/
@State(Scope.Benchmark)
@Warmup(iterations = 20)
@Warmup(iterations = 5)
@BenchmarkMode({ Mode.AverageTime })
@Fork(value = 1, jvmArgs = { "-Xms1G", "-Xmx1G", })
@Measurement(iterations = 10)
@Measurement(iterations = 5)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
public class MemValueFactoryConcurrentBenchmark extends BaseConcurrentBenchmark {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@
import org.openjdk.jmh.runner.options.OptionsBuilder;

@State(Scope.Benchmark)
@Warmup(iterations = 20)
@Warmup(iterations = 5)
@BenchmarkMode({ Mode.AverageTime })
//@Fork(value = 1, jvmArgs = {"-Xms2G", "-Xmx2G", "-XX:+UnlockCommercialFeatures", "-XX:StartFlightRecording=delay=5s,duration=60s,filename=recording.jfr,settings=profile", "-XX:FlightRecorderOptions=samplethreads=true,stackdepth=1024", "-XX:+UnlockDiagnosticVMOptions", "-XX:+DebugNonSafepoints"})
@Fork(value = 1, jvmArgs = { "-Xms2G", "-Xmx2G" })
@Measurement(iterations = 10)
@Measurement(iterations = 5)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
public class NotifyingSailBenchmark {

Expand All @@ -76,7 +76,6 @@ public class NotifyingSailBenchmark {
public static void main(String[] args) throws RunnerException {
Options opt = new OptionsBuilder()
.include("NotifyingSailBenchmark.load") // adapt to run other benchmark tests
// .addProfiler("stack", "lines=20;period=1;top=20")
.forks(1)
.build();

Expand Down
Loading

0 comments on commit f0eb270

Please sign in to comment.