Skip to content

Introduce Netty benchmark suite. #1647

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Apr 2, 2025
Merged
17 changes: 17 additions & 0 deletions .evergreen/.evg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,8 @@ functions:
type: test
params:
working_dir: "src"
env:
PROVIDER: ${PROVIDER}
script: |
${PREPARE_SHELL}
PROJECT_DIRECTORY=${PROJECT_DIRECTORY} .evergreen/run-perf-tests.sh
Expand Down Expand Up @@ -1560,6 +1562,20 @@ tasks:
- func: "run perf tests"
- func: "send dashboard data"

- name: "perf-netty"
tags: [ "perf" ]
commands:
- func: "bootstrap mongo-orchestration"
vars:
VERSION: "v8.0-perf"
TOPOLOGY: "server"
SSL: "nossl"
AUTH: "noauth"
- func: "run perf tests"
vars:
PROVIDER: "Netty"
- func: "send dashboard data"

- name: "aws-lambda-deployed-task"
commands:
- command: ec2.assume_role
Expand Down Expand Up @@ -2312,6 +2328,7 @@ buildvariants:
run_on: rhel90-dbx-perf-large
tasks:
- name: "perf"
- name: "perf-netty"

- name: plain-auth-test
display_name: "PLAIN (LDAP) Auth test"
Expand Down
8 changes: 7 additions & 1 deletion .evergreen/run-perf-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,14 @@ RELATIVE_DIR_PATH="$(dirname "${BASH_SOURCE:-$0}")"
export TEST_PATH="${PROJECT_DIRECTORY}/driver-performance-test-data/"
export OUTPUT_FILE="${PROJECT_DIRECTORY}/results.json"

if [ "${PROVIDER}" = "Netty" ]; then
TASK="driver-benchmarks:runNetty"
else
TASK="driver-benchmarks:run"
fi

start_time=$(date +%s)
./gradlew -Dorg.mongodb.benchmarks.data=${TEST_PATH} -Dorg.mongodb.benchmarks.output=${OUTPUT_FILE} driver-benchmarks:run
./gradlew -Dorg.mongodb.benchmarks.data=${TEST_PATH} -Dorg.mongodb.benchmarks.output=${OUTPUT_FILE} ${TASK}
end_time=$(date +%s)
elapsed_secs=$((end_time-start_time))

13 changes: 13 additions & 0 deletions driver-benchmarks/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,14 @@ sourceSets {
dependencies {
api(project(":driver-sync"))
api(project(":mongodb-crypt"))

implementation(platform(libs.netty.bom))
implementation(libs.bundles.netty)

implementation(libs.logback.classic)
implementation(libs.jmh.core)
annotationProcessor(libs.jmh.generator.annprocess)

}

tasks.register<JavaExec>("jmh") {
Expand All @@ -49,6 +54,14 @@ tasks.register<JavaExec>("jmh") {
classpath = sourceSets.main.get().runtimeClasspath
}

tasks.register<JavaExec>("runNetty") {
group = "application"
description = "Run the Netty main class."
mainClass.set("com.mongodb.benchmark.benchmarks.netty.BenchmarkNettyProviderSuite")
classpath = sourceSets["main"].runtimeClasspath
jvmArgs = application.applicationDefaultJvmArgs.toList()
}

tasks.withType<Javadoc>().configureEach {
enabled = false
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,14 @@ public abstract class AbstractBsonDocumentBenchmark<T> extends Benchmark {

protected final PowerOfTwoBufferPool bufferPool = PowerOfTwoBufferPool.DEFAULT;
protected final Codec<T> codec;

private final String name;
private final String resourcePath;

protected T document;
protected byte[] documentBytes;
private int fileLength;

public AbstractBsonDocumentBenchmark(final String name, final String resourcePath, final Codec<T> codec) {
this.name = name;
super(name);
this.resourcePath = resourcePath;
this.codec = codec;
}
Expand All @@ -58,11 +56,6 @@ public void setUp() throws IOException {
documentBytes = getDocumentAsBuffer(document);
}

@Override
public String getName() {
return name;
}

@Override
public int getBytesPerRun() {
return fileLength * NUM_INTERNAL_ITERATIONS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ public abstract class AbstractCollectionWriteBenchmark<T> extends AbstractWriteB

protected MongoCollection<T> collection;
protected MongoDatabase database;

private final String name;
private final Class<T> clazz;

protected AbstractCollectionWriteBenchmark(final String name,
Expand All @@ -34,7 +32,6 @@ protected AbstractCollectionWriteBenchmark(final String name,
int numDocuments,
final Class<T> clazz) {
super(name, resourcePath, numIterations, numDocuments, clazz);
this.name = name;
this.clazz = clazz;
}

Expand All @@ -51,9 +48,4 @@ public void before() throws Exception {
super.before();
collection.drop();
}

@Override
public String getName() {
return name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,17 @@
public abstract class AbstractFindBenchmark<T> extends AbstractMongoBenchmark {
protected MongoCollection<T> collection;

private final String name;
private final String resourcePath;
private final Class<T> clazz;

private int fileLength;

public AbstractFindBenchmark(final String name, final String resourcePath, final Class<T> clazz) {
this.name = name;
super(name);
this.resourcePath = resourcePath;
this.clazz = clazz;
}

@Override
public String getName() {
return name;
}

public void setUp() throws Exception {
super.setUp();
collection = client.getDatabase(DATABASE_NAME).getCollection(COLLECTION_NAME, clazz);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public abstract class AbstractGridFSBenchmark extends AbstractMongoBenchmark {
protected GridFSBucket bucket;
protected byte[] fileBytes;

public AbstractGridFSBenchmark(final String resourcePath) {
public AbstractGridFSBenchmark(final String name, final String resourcePath) {
super(name);
this.resourcePath = resourcePath;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package com.mongodb.benchmark.benchmarks;

import com.mongodb.MongoClientSettings;
import com.mongodb.MongoNamespace;
import com.mongodb.benchmark.framework.Benchmark;
import com.mongodb.client.MongoClient;
Expand All @@ -36,17 +37,29 @@ public abstract class AbstractMongoBenchmark extends Benchmark {
protected static final String COLLECTION_NAME = "corpus";
protected static final MongoNamespace NAMESPACE = new MongoNamespace(
AbstractMongoBenchmark.DATABASE_NAME, AbstractMongoBenchmark.COLLECTION_NAME);
protected MongoClientSettings mongoClientSettings;

public AbstractMongoBenchmark(final String name) {
super(name);
}

protected MongoClient client;

public void setUp() throws Exception {
client = MongoClients.create();
if (mongoClientSettings != null) {
client = MongoClients.create(mongoClientSettings);
} else {
client = MongoClients.create();
}
}

@Override
public void tearDown() throws Exception {
client.close();
}

public AbstractMongoBenchmark applyMongoClientSettings(final MongoClientSettings mongoClientSettings) {
this.mongoClientSettings = mongoClientSettings;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

public abstract class AbstractWriteBenchmark<T> extends AbstractMongoBenchmark {
protected static final Bson EMPTY_FILTER = Filters.empty();
private final String name;
private final String resourcePath;
private final Class<T> clazz;
private byte[] bytes;
Expand All @@ -41,7 +40,7 @@ protected AbstractWriteBenchmark(final String name,
int numInternalIterations,
int numDocuments,
final Class<T> clazz) {
this.name = name;
super(name);
this.resourcePath = resourcePath;
this.clazz = clazz;
this.numInternalIterations = numInternalIterations;
Expand All @@ -57,11 +56,6 @@ public void setUp() throws Exception {
document = codec.decode(new JsonReader(new String(bytes, StandardCharsets.UTF_8)), DecoderContext.builder().build());
}

@Override
public String getName() {
return name;
}

protected T createDocument() {
Codec<T> codec = client.getCodecRegistry().get(clazz);
return codec.decode(new JsonReader(new String(bytes, StandardCharsets.UTF_8)), DecoderContext.builder().build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@
@SuppressWarnings({"rawtypes", "unchecked"})
public class BenchmarkSuite {

private static final int NUM_WARMUP_ITERATIONS = 1;
private static final int NUM_ITERATIONS = 100;
private static final int MIN_TIME_SECONDS = 60;
private static final int MAX_TIME_SECONDS = 300;
protected static final int NUM_WARMUP_ITERATIONS = 1;
protected static final int NUM_ITERATIONS = 100;
protected static final int MIN_TIME_SECONDS = 60;
protected static final int MAX_TIME_SECONDS = 300;

private static final Class DOCUMENT_CLASS = Document.class;
private static final IdRemover<Document> ID_REMOVER = document -> document.remove("_id");
private static final Codec<Document> DOCUMENT_CODEC = getDefaultCodecRegistry().get(DOCUMENT_CLASS);
protected static final Class DOCUMENT_CLASS = Document.class;
protected static final IdRemover<Document> ID_REMOVER = document -> document.remove("_id");
protected static final Codec<Document> DOCUMENT_CODEC = getDefaultCodecRegistry().get(DOCUMENT_CLASS);

private static final List<BenchmarkResultWriter> WRITERS = Arrays.asList(
protected static final List<BenchmarkResultWriter> WRITERS = Arrays.asList(
new EvergreenBenchmarkResultWriter());

public static void main(String[] args) throws Exception {
Expand Down Expand Up @@ -120,7 +120,7 @@ private static void runMongoCryptBenchMarks() throws InterruptedException {
}
}

private static void runBenchmark(final Benchmark benchmark) throws Exception {
protected static void runBenchmark(final Benchmark benchmark) throws Exception {
long startTime = System.currentTimeMillis();
BenchmarkResult benchmarkResult = new BenchmarkRunner(benchmark, NUM_WARMUP_ITERATIONS, NUM_ITERATIONS, MIN_TIME_SECONDS,
MAX_TIME_SECONDS).run();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,7 @@ public class GridFSDownloadBenchmark extends AbstractGridFSBenchmark {
private ObjectId fileId;

public GridFSDownloadBenchmark(final String resourcePath) {
super(resourcePath);
}

@Override
public String getName() {
return "GridFS download";
super("GridFS download", resourcePath);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;


public class GridFSMultiFileDownloadBenchmark extends AbstractMongoBenchmark {

private GridFSBucket bucket;
Expand All @@ -43,9 +44,8 @@ public class GridFSMultiFileDownloadBenchmark extends AbstractMongoBenchmark {

private File tempDirectory;

@Override
public String getName() {
return "GridFS multi-file download";
public GridFSMultiFileDownloadBenchmark() {
super("GridFS multi-file download");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;


public class GridFSMultiFileUploadBenchmark extends AbstractMongoBenchmark {

private MongoDatabase database;
private GridFSBucket bucket;

private ExecutorService fileService;

@Override
public String getName() {
return "GridFS multi-file upload";
public GridFSMultiFileUploadBenchmark() {
super("GridFS multi-file upload");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,7 @@
public class GridFSUploadBenchmark extends AbstractGridFSBenchmark {

public GridFSUploadBenchmark(final String resourcePath) {
super(resourcePath);
}

@Override
public String getName() {
return "GridFS upload";
super("GridFS upload", resourcePath);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@ public class MultiFileExportBenchmark extends AbstractMongoBenchmark {
private ExecutorService documentReadingService;
private File tempDirectory;

@Override
public String getName() {
return "LDJSON multi-file export";
public MultiFileExportBenchmark() {
super("LDJSON multi-file export");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ public class MultiFileImportBenchmark extends AbstractMongoBenchmark {
private ExecutorService fileReadingService;
private ExecutorService documentWritingService;

public MultiFileImportBenchmark() {
super("LDJSON multi-file import");
}

@Override
public void setUp() throws Exception {
super.setUp();
Expand Down Expand Up @@ -77,12 +81,6 @@ public void tearDown() throws Exception {
super.tearDown();
}

@Override
public String getName() {
return "LDJSON multi-file import";
}


@Override
public void run() throws InterruptedException {
CountDownLatch latch = new CountDownLatch(500);
Expand Down
Loading