From 5179c306a47d3511091c7be336dd02414878d4c3 Mon Sep 17 00:00:00 2001 From: "slav.babanin" Date: Mon, 24 Mar 2025 14:12:46 -0700 Subject: [PATCH 01/11] Add Collection and Client BulkWrite benchmarks. JAVA-5545 --- .../benchmark/benchmarks/BenchmarkSuite.java | 14 ++++- .../benchmarks/ClientBulkWriteBenchmark.java | 55 +++++++++++++++++++ .../CollectionBulkWriteBenchmark.java | 52 ++++++++++++++++++ .../benchmarks/InsertManyBenchmark.java | 2 +- 4 files changed, 120 insertions(+), 3 deletions(-) create mode 100644 driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/ClientBulkWriteBenchmark.java create mode 100644 driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/CollectionBulkWriteBenchmark.java diff --git a/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/BenchmarkSuite.java b/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/BenchmarkSuite.java index 2260e0ed80a..a0f95fe67dc 100644 --- a/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/BenchmarkSuite.java +++ b/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/BenchmarkSuite.java @@ -70,17 +70,27 @@ private static void runBenchmarks() runBenchmark(new RunCommandBenchmark<>(DOCUMENT_CODEC)); runBenchmark(new FindOneBenchmark("single_and_multi_document/tweet.json", BenchmarkSuite.DOCUMENT_CLASS)); - runBenchmark(new InsertOneBenchmark("Small", "./single_and_multi_document/small_doc.json", 10000, + runBenchmark(new InsertOneBenchmark("Small", "./single_and_multi_document/small_doc.json", 10_000, DOCUMENT_CLASS, ID_REMOVER)); runBenchmark(new InsertOneBenchmark("Large", "./single_and_multi_document/large_doc.json", 10, DOCUMENT_CLASS, ID_REMOVER)); runBenchmark(new FindManyBenchmark("single_and_multi_document/tweet.json", BenchmarkSuite.DOCUMENT_CLASS)); - runBenchmark(new InsertManyBenchmark("Small", "./single_and_multi_document/small_doc.json", 10000, + runBenchmark(new InsertManyBenchmark("Small", "./single_and_multi_document/small_doc.json", 10_000, DOCUMENT_CLASS)); runBenchmark(new InsertManyBenchmark("Large", "./single_and_multi_document/large_doc.json", 10, DOCUMENT_CLASS)); + runBenchmark(new CollectionBulkWriteBenchmark<>("Small", "./single_and_multi_document/small_doc.json", 10_000, + DOCUMENT_CLASS)); + runBenchmark(new CollectionBulkWriteBenchmark<>("Large", "./single_and_multi_document/large_doc.json", 10, + DOCUMENT_CLASS)); + + runBenchmark(new ClientBulkWriteBenchmark<>("Small", "./single_and_multi_document/small_doc.json", 10_000, + DOCUMENT_CLASS)); + runBenchmark(new ClientBulkWriteBenchmark<>("Large", "./single_and_multi_document/large_doc.json", 10, + DOCUMENT_CLASS)); + runBenchmark(new GridFSUploadBenchmark("single_and_multi_document/gridfs_large.bin")); runBenchmark(new GridFSDownloadBenchmark("single_and_multi_document/gridfs_large.bin")); diff --git a/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/ClientBulkWriteBenchmark.java b/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/ClientBulkWriteBenchmark.java new file mode 100644 index 00000000000..1c1b9fb2822 --- /dev/null +++ b/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/ClientBulkWriteBenchmark.java @@ -0,0 +1,55 @@ +/* + * Copyright 2016-present MongoDB, Inc. + * + * Licensed 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 com.mongodb.benchmark.benchmarks; + +import com.mongodb.MongoNamespace; +import com.mongodb.client.model.bulk.ClientNamespacedInsertOneModel; +import com.mongodb.client.model.bulk.ClientNamespacedWriteModel; + +import java.util.ArrayList; +import java.util.List; + +public class ClientBulkWriteBenchmark extends InsertManyBenchmark { + private static final MongoNamespace NAMESPACE = new MongoNamespace(DATABASE_NAME, COLLECTION_NAME); + private final List documentList; + + public ClientBulkWriteBenchmark(final String name, final String resourcePath, final int numDocuments, final Class clazz) { + super(name + " doc Client BulkWrite insert", resourcePath, numDocuments, clazz); + documentList = new ArrayList<>(numDocuments); + } + + @Override + public void setUp() throws Exception { + super.setUp(); + } + + @Override + public void before() throws Exception { + super.before(); + + documentList.clear(); + for (int i = 0; i < numDocuments; i++) { + documentList.add(ClientNamespacedWriteModel.insertOne(NAMESPACE, createDocument())); + } + } + + @Override + public void run() { + client.bulkWrite(documentList); + } +} diff --git a/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/CollectionBulkWriteBenchmark.java b/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/CollectionBulkWriteBenchmark.java new file mode 100644 index 00000000000..63a77de7743 --- /dev/null +++ b/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/CollectionBulkWriteBenchmark.java @@ -0,0 +1,52 @@ +/* + * Copyright 2016-present MongoDB, Inc. + * + * Licensed 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 com.mongodb.benchmark.benchmarks; + +import com.mongodb.client.model.InsertOneModel; + +import java.util.ArrayList; +import java.util.List; + +public class CollectionBulkWriteBenchmark extends InsertManyBenchmark { + private final List> documentList; + + public CollectionBulkWriteBenchmark(final String name, final String resourcePath, final int numDocuments, final Class clazz) { + super(name + " doc Collection BulkWrite insert", resourcePath, numDocuments, clazz); + documentList = new ArrayList<>(numDocuments); + } + + @Override + public void setUp() throws Exception { + super.setUp(); + } + + @Override + public void before() throws Exception { + super.before(); + + documentList.clear(); + for (int i = 0; i < numDocuments; i++) { + documentList.add(new InsertOneModel<>((createDocument()))); + } + } + + @Override + public void run() { + collection.bulkWrite(documentList); + } +} diff --git a/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/InsertManyBenchmark.java b/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/InsertManyBenchmark.java index 094520afcd2..45ed1628a1f 100644 --- a/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/InsertManyBenchmark.java +++ b/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/InsertManyBenchmark.java @@ -21,7 +21,7 @@ import java.util.List; public class InsertManyBenchmark extends AbstractInsertBenchmark { - private final int numDocuments; + protected final int numDocuments; private final List documentList; public InsertManyBenchmark(final String name, final String resourcePath, final int numDocuments, final Class clazz) { From b4ef6c2e7a054a9109d0389fa47ca254012e9484 Mon Sep 17 00:00:00 2001 From: "slav.babanin" Date: Mon, 24 Mar 2025 20:31:37 -0700 Subject: [PATCH 02/11] Add Mixed Client Bulk Write. JAVA-5545 --- .../AbstractCollectionWriteBenchmark.java | 59 ++++++++++++ .../benchmarks/AbstractMongoBenchmark.java | 3 + ...hmark.java => AbstractWriteBenchmark.java} | 45 ++++----- .../benchmark/benchmarks/BenchmarkSuite.java | 9 ++ .../benchmarks/InsertManyBenchmark.java | 11 +-- .../benchmarks/InsertOneBenchmark.java | 10 +- .../{ => bulk}/ClientBulkWriteBenchmark.java | 25 ++--- .../CollectionBulkWriteBenchmark.java | 24 ++--- .../bulk/MixedClientBulkWriteBenchmark.java | 96 +++++++++++++++++++ .../MixedCollectionBulkWriteBenchmark.java | 58 +++++++++++ 10 files changed, 268 insertions(+), 72 deletions(-) create mode 100644 driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/AbstractCollectionWriteBenchmark.java rename driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/{AbstractInsertBenchmark.java => AbstractWriteBenchmark.java} (68%) rename driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/{ => bulk}/ClientBulkWriteBenchmark.java (64%) rename driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/{ => bulk}/CollectionBulkWriteBenchmark.java (67%) create mode 100644 driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/bulk/MixedClientBulkWriteBenchmark.java create mode 100644 driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/bulk/MixedCollectionBulkWriteBenchmark.java diff --git a/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/AbstractCollectionWriteBenchmark.java b/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/AbstractCollectionWriteBenchmark.java new file mode 100644 index 00000000000..867f20cd84c --- /dev/null +++ b/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/AbstractCollectionWriteBenchmark.java @@ -0,0 +1,59 @@ +/* + * Copyright 2016-present MongoDB, Inc. + * + * Licensed 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 com.mongodb.benchmark.benchmarks; + +import com.mongodb.client.MongoCollection; +import com.mongodb.client.MongoDatabase; + +public abstract class AbstractCollectionWriteBenchmark extends AbstractWriteBenchmark { + + protected MongoCollection collection; + protected MongoDatabase database; + + private final String name; + private final Class clazz; + + protected AbstractCollectionWriteBenchmark(final String name, + final String resourcePath, + int numIterations, + int numberDocuments, + final Class clazz) { + super(name, resourcePath, numIterations, numberDocuments, clazz); + this.name = name; + this.clazz = clazz; + } + + @Override + public void setUp() throws Exception { + super.setUp(); + database = client.getDatabase(DATABASE_NAME); + collection = database.getCollection(COLLECTION_NAME, clazz); + database.drop(); + } + + @Override + public void before() throws Exception { + super.before(); + collection.drop(); + } + + @Override + public String getName() { + return name; + } +} diff --git a/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/AbstractMongoBenchmark.java b/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/AbstractMongoBenchmark.java index 71426525ae5..5e6fba464f8 100644 --- a/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/AbstractMongoBenchmark.java +++ b/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/AbstractMongoBenchmark.java @@ -17,6 +17,7 @@ package com.mongodb.benchmark.benchmarks; +import com.mongodb.MongoNamespace; import com.mongodb.benchmark.framework.Benchmark; import com.mongodb.client.MongoClient; import com.mongodb.client.MongoClients; @@ -33,6 +34,8 @@ public abstract class AbstractMongoBenchmark extends Benchmark { protected static final String DATABASE_NAME = "perftest"; protected static final String COLLECTION_NAME = "corpus"; + protected static final MongoNamespace NAMESPACE = new MongoNamespace( + AbstractMongoBenchmark.DATABASE_NAME, AbstractMongoBenchmark.COLLECTION_NAME); protected MongoClient client; diff --git a/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/AbstractInsertBenchmark.java b/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/AbstractWriteBenchmark.java similarity index 68% rename from driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/AbstractInsertBenchmark.java rename to driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/AbstractWriteBenchmark.java index 561d5c502b5..c7828b1a2df 100644 --- a/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/AbstractInsertBenchmark.java +++ b/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/AbstractWriteBenchmark.java @@ -4,7 +4,7 @@ * Licensed 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 @@ -17,62 +17,55 @@ package com.mongodb.benchmark.benchmarks; -import com.mongodb.client.MongoCollection; -import com.mongodb.client.MongoDatabase; import org.bson.codecs.Codec; import org.bson.codecs.DecoderContext; import org.bson.json.JsonReader; import java.nio.charset.StandardCharsets; -public abstract class AbstractInsertBenchmark extends AbstractMongoBenchmark { - - protected MongoCollection collection; - +public abstract class AbstractWriteBenchmark extends AbstractMongoBenchmark { private final String name; private final String resourcePath; private final Class clazz; private byte[] bytes; protected int fileLength; protected T document; - - protected AbstractInsertBenchmark(final String name, final String resourcePath, final Class clazz) { + protected int numIterations; + protected int numDocuments; + + protected AbstractWriteBenchmark(final String name, + final String resourcePath, + int numIterations, + int numDocuments, + final Class clazz) { this.name = name; this.resourcePath = resourcePath; this.clazz = clazz; + this.numIterations = numIterations; + this.numDocuments = numDocuments; } @Override public void setUp() throws Exception { super.setUp(); - MongoDatabase database = client.getDatabase(DATABASE_NAME); - - collection = database.getCollection(COLLECTION_NAME, clazz); - - database.drop(); bytes = readAllBytesFromRelativePath(resourcePath); - fileLength = bytes.length; - - Codec codec = collection.getCodecRegistry().get(clazz); - + Codec codec = client.getCodecRegistry().get(clazz); document = codec.decode(new JsonReader(new String(bytes, StandardCharsets.UTF_8)), DecoderContext.builder().build()); } - @Override - public void before() throws Exception { - super.before(); - collection.drop(); - } - @Override public String getName() { return name; } protected T createDocument() { - Codec codec = collection.getCodecRegistry().get(clazz); - + Codec codec = client.getCodecRegistry().get(clazz); return codec.decode(new JsonReader(new String(bytes, StandardCharsets.UTF_8)), DecoderContext.builder().build()); } + + @Override + public int getBytesPerRun() { + return fileLength * numIterations * numDocuments; + } } diff --git a/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/BenchmarkSuite.java b/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/BenchmarkSuite.java index a0f95fe67dc..9d432e7c7e9 100644 --- a/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/BenchmarkSuite.java +++ b/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/BenchmarkSuite.java @@ -17,6 +17,10 @@ package com.mongodb.benchmark.benchmarks; +import com.mongodb.benchmark.benchmarks.bulk.ClientBulkWriteBenchmark; +import com.mongodb.benchmark.benchmarks.bulk.CollectionBulkWriteBenchmark; +import com.mongodb.benchmark.benchmarks.bulk.MixedClientBulkWriteBenchmark; +import com.mongodb.benchmark.benchmarks.bulk.MixedCollectionBulkWriteBenchmark; import com.mongodb.benchmark.framework.Benchmark; import com.mongodb.benchmark.framework.BenchmarkResult; import com.mongodb.benchmark.framework.BenchmarkResultWriter; @@ -91,6 +95,11 @@ private static void runBenchmarks() runBenchmark(new ClientBulkWriteBenchmark<>("Large", "./single_and_multi_document/large_doc.json", 10, DOCUMENT_CLASS)); + runBenchmark(new MixedCollectionBulkWriteBenchmark<>("./single_and_multi_document/small_doc.json", 10_000, + DOCUMENT_CLASS)); + runBenchmark(new MixedClientBulkWriteBenchmark<>("./single_and_multi_document/large_doc.json", 10, + DOCUMENT_CLASS)); + runBenchmark(new GridFSUploadBenchmark("single_and_multi_document/gridfs_large.bin")); runBenchmark(new GridFSDownloadBenchmark("single_and_multi_document/gridfs_large.bin")); diff --git a/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/InsertManyBenchmark.java b/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/InsertManyBenchmark.java index 45ed1628a1f..a67466740e8 100644 --- a/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/InsertManyBenchmark.java +++ b/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/InsertManyBenchmark.java @@ -20,13 +20,11 @@ import java.util.ArrayList; import java.util.List; -public class InsertManyBenchmark extends AbstractInsertBenchmark { - protected final int numDocuments; +public class InsertManyBenchmark extends AbstractCollectionWriteBenchmark { private final List documentList; public InsertManyBenchmark(final String name, final String resourcePath, final int numDocuments, final Class clazz) { - super(name + " doc bulk insert", resourcePath, clazz); - this.numDocuments = numDocuments; + super(name + " doc bulk insert", resourcePath, 1, numDocuments, clazz); documentList = new ArrayList<>(numDocuments); } @@ -48,9 +46,4 @@ public void before() throws Exception { public void run() { collection.insertMany(documentList); } - - @Override - public int getBytesPerRun() { - return fileLength * numDocuments; - } } diff --git a/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/InsertOneBenchmark.java b/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/InsertOneBenchmark.java index 575a5b4b235..af6f91b91df 100644 --- a/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/InsertOneBenchmark.java +++ b/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/InsertOneBenchmark.java @@ -17,13 +17,13 @@ package com.mongodb.benchmark.benchmarks; -public class InsertOneBenchmark extends AbstractInsertBenchmark { +public class InsertOneBenchmark extends AbstractCollectionWriteBenchmark { private final int numIterations; private final IdRemover idRemover; public InsertOneBenchmark(final String name, final String resourcePath, final int numIterations, final Class clazz, final IdRemover idRemover) { - super(name + " doc insertOne", resourcePath, clazz); + super(name + " doc insertOne", resourcePath, numIterations, 1, clazz); this.numIterations = numIterations; this.idRemover = idRemover; } @@ -35,10 +35,4 @@ public void run() { collection.insertOne(document); } } - - @Override - public int getBytesPerRun() { - return fileLength * numIterations; - } - } diff --git a/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/ClientBulkWriteBenchmark.java b/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/bulk/ClientBulkWriteBenchmark.java similarity index 64% rename from driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/ClientBulkWriteBenchmark.java rename to driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/bulk/ClientBulkWriteBenchmark.java index 1c1b9fb2822..3926192ec4b 100644 --- a/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/ClientBulkWriteBenchmark.java +++ b/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/bulk/ClientBulkWriteBenchmark.java @@ -15,41 +15,36 @@ * */ -package com.mongodb.benchmark.benchmarks; +package com.mongodb.benchmark.benchmarks.bulk; -import com.mongodb.MongoNamespace; +import com.mongodb.benchmark.benchmarks.AbstractCollectionWriteBenchmark; import com.mongodb.client.model.bulk.ClientNamespacedInsertOneModel; import com.mongodb.client.model.bulk.ClientNamespacedWriteModel; import java.util.ArrayList; import java.util.List; -public class ClientBulkWriteBenchmark extends InsertManyBenchmark { - private static final MongoNamespace NAMESPACE = new MongoNamespace(DATABASE_NAME, COLLECTION_NAME); - private final List documentList; +public class ClientBulkWriteBenchmark extends AbstractCollectionWriteBenchmark { + private final List modelList; public ClientBulkWriteBenchmark(final String name, final String resourcePath, final int numDocuments, final Class clazz) { - super(name + " doc Client BulkWrite insert", resourcePath, numDocuments, clazz); - documentList = new ArrayList<>(numDocuments); - } - - @Override - public void setUp() throws Exception { - super.setUp(); + super(name + " doc Client BulkWrite insert", resourcePath, 1, numDocuments, clazz); + modelList = new ArrayList<>(numDocuments); } @Override public void before() throws Exception { super.before(); + database.createCollection(COLLECTION_NAME); - documentList.clear(); + modelList.clear(); for (int i = 0; i < numDocuments; i++) { - documentList.add(ClientNamespacedWriteModel.insertOne(NAMESPACE, createDocument())); + modelList.add(ClientNamespacedWriteModel.insertOne(NAMESPACE, createDocument())); } } @Override public void run() { - client.bulkWrite(documentList); + client.bulkWrite(modelList); } } diff --git a/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/CollectionBulkWriteBenchmark.java b/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/bulk/CollectionBulkWriteBenchmark.java similarity index 67% rename from driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/CollectionBulkWriteBenchmark.java rename to driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/bulk/CollectionBulkWriteBenchmark.java index 63a77de7743..6a0d74d4736 100644 --- a/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/CollectionBulkWriteBenchmark.java +++ b/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/bulk/CollectionBulkWriteBenchmark.java @@ -15,38 +15,34 @@ * */ -package com.mongodb.benchmark.benchmarks; +package com.mongodb.benchmark.benchmarks.bulk; +import com.mongodb.benchmark.benchmarks.AbstractCollectionWriteBenchmark; import com.mongodb.client.model.InsertOneModel; import java.util.ArrayList; import java.util.List; -public class CollectionBulkWriteBenchmark extends InsertManyBenchmark { - private final List> documentList; +public class CollectionBulkWriteBenchmark extends AbstractCollectionWriteBenchmark { + private final List> modelList; public CollectionBulkWriteBenchmark(final String name, final String resourcePath, final int numDocuments, final Class clazz) { - super(name + " doc Collection BulkWrite insert", resourcePath, numDocuments, clazz); - documentList = new ArrayList<>(numDocuments); - } - - @Override - public void setUp() throws Exception { - super.setUp(); + super(name + " doc Collection BulkWrite insert", resourcePath, 1, numDocuments, clazz); + modelList = new ArrayList<>(numDocuments); } @Override public void before() throws Exception { super.before(); - - documentList.clear(); + database.createCollection(COLLECTION_NAME); + modelList.clear(); for (int i = 0; i < numDocuments; i++) { - documentList.add(new InsertOneModel<>((createDocument()))); + modelList.add(new InsertOneModel<>((createDocument()))); } } @Override public void run() { - collection.bulkWrite(documentList); + collection.bulkWrite(modelList); } } diff --git a/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/bulk/MixedClientBulkWriteBenchmark.java b/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/bulk/MixedClientBulkWriteBenchmark.java new file mode 100644 index 00000000000..bf90aa24d5d --- /dev/null +++ b/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/bulk/MixedClientBulkWriteBenchmark.java @@ -0,0 +1,96 @@ +/* + * Copyright 2016-present MongoDB, Inc. + * + * Licensed 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 com.mongodb.benchmark.benchmarks.bulk; + +import com.mongodb.MongoNamespace; +import com.mongodb.benchmark.benchmarks.AbstractMongoBenchmark; +import com.mongodb.benchmark.benchmarks.AbstractWriteBenchmark; +import com.mongodb.client.MongoDatabase; +import com.mongodb.client.model.Filters; +import com.mongodb.client.model.bulk.ClientNamespacedWriteModel; + +import java.util.ArrayList; +import java.util.List; + +import static com.mongodb.client.model.bulk.ClientNamespacedWriteModel.deleteOne; +import static com.mongodb.client.model.bulk.ClientNamespacedWriteModel.insertOne; +import static com.mongodb.client.model.bulk.ClientNamespacedWriteModel.replaceOne; + +public class MixedClientBulkWriteBenchmark extends AbstractWriteBenchmark { + private static final int NAMESPACES_COUNT = 10; + private MongoDatabase database; + private final List modelList; + private List namespaces; + + public MixedClientBulkWriteBenchmark(final String resourcePath, final int numDocuments, final Class clazz) { + super("Small doc Client BulkWrite Mixed Operations", resourcePath, 1, numDocuments * 3, clazz); + modelList = new ArrayList<>(super.numDocuments); + namespaces = new ArrayList<>(NAMESPACES_COUNT); + } + + @Override + public void setUp() throws Exception { + super.setUp(); + database = client.getDatabase(DATABASE_NAME); + database.drop(); + + namespaces = new ArrayList<>(); + long time = System.currentTimeMillis(); + for (int i = 1; i <= NAMESPACES_COUNT; i++) { + namespaces.add(new MongoNamespace(AbstractMongoBenchmark.DATABASE_NAME, AbstractMongoBenchmark.COLLECTION_NAME + "_" + i)); + } + } + + @Override + public void before() throws Exception { + super.before(); + database.drop(); + database = client.getDatabase(DATABASE_NAME); + + for (MongoNamespace namespace : namespaces) { + database.createCollection(namespace.getCollectionName()); + } + + modelList.clear(); + long time = System.currentTimeMillis(); + for (int i = 0; i < numDocuments; i++) { + MongoNamespace namespace = namespaces.get(i % NAMESPACES_COUNT); + modelList.add(insertOne( + namespace, + createDocument())); + modelList.add(replaceOne( + namespace, + Filters.empty(), + createDocument())); + modelList.add(deleteOne( + namespace, + Filters.empty())); + } + System.out.println("Time to create documents: " + (System.currentTimeMillis() - time)); + } + + @Override + public void run() { + client.bulkWrite(modelList); + } + + @Override + public int getBytesPerRun() { + return 0; + } +} diff --git a/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/bulk/MixedCollectionBulkWriteBenchmark.java b/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/bulk/MixedCollectionBulkWriteBenchmark.java new file mode 100644 index 00000000000..549ef7ef39c --- /dev/null +++ b/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/bulk/MixedCollectionBulkWriteBenchmark.java @@ -0,0 +1,58 @@ +/* + * Copyright 2016-present MongoDB, Inc. + * + * Licensed 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 com.mongodb.benchmark.benchmarks.bulk; + +import com.mongodb.benchmark.benchmarks.AbstractCollectionWriteBenchmark; +import com.mongodb.client.model.DeleteOneModel; +import com.mongodb.client.model.Filters; +import com.mongodb.client.model.InsertOneModel; +import com.mongodb.client.model.ReplaceOneModel; +import com.mongodb.client.model.WriteModel; + +import java.util.ArrayList; +import java.util.List; + +public class MixedCollectionBulkWriteBenchmark extends AbstractCollectionWriteBenchmark { + private final List> modelList; + + public MixedCollectionBulkWriteBenchmark(final String resourcePath, final int numDocuments, final Class clazz) { + super("Small doc Collection BulkWrite Mixed Operations", resourcePath, 1, numDocuments * 3, clazz); + modelList = new ArrayList<>(super.numDocuments); + } + + + @Override + public void before() throws Exception { + super.before(); + database.createCollection(COLLECTION_NAME); + + modelList.clear(); + long time = System.currentTimeMillis(); + for (int i = 0; i < numDocuments; i++) { + modelList.add(new InsertOneModel<>((createDocument()))); + modelList.add(new ReplaceOneModel<>(Filters.empty(), createDocument())); + modelList.add(new DeleteOneModel<>(Filters.empty())); + } + System.out.println("Time to create models: " + (System.currentTimeMillis() - time)); + } + + @Override + public void run() { + collection.bulkWrite(modelList); + } +} From f408b4a0e4a6cce5320ca261ba6e7f5af7effe2a Mon Sep 17 00:00:00 2001 From: "slav.babanin" Date: Mon, 24 Mar 2025 20:47:26 -0700 Subject: [PATCH 03/11] Remove logs. JAVA-5545 --- .../benchmarks/bulk/MixedClientBulkWriteBenchmark.java | 3 --- .../benchmarks/bulk/MixedCollectionBulkWriteBenchmark.java | 2 -- 2 files changed, 5 deletions(-) diff --git a/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/bulk/MixedClientBulkWriteBenchmark.java b/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/bulk/MixedClientBulkWriteBenchmark.java index bf90aa24d5d..d2566166c3d 100644 --- a/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/bulk/MixedClientBulkWriteBenchmark.java +++ b/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/bulk/MixedClientBulkWriteBenchmark.java @@ -50,7 +50,6 @@ public void setUp() throws Exception { database.drop(); namespaces = new ArrayList<>(); - long time = System.currentTimeMillis(); for (int i = 1; i <= NAMESPACES_COUNT; i++) { namespaces.add(new MongoNamespace(AbstractMongoBenchmark.DATABASE_NAME, AbstractMongoBenchmark.COLLECTION_NAME + "_" + i)); } @@ -67,7 +66,6 @@ public void before() throws Exception { } modelList.clear(); - long time = System.currentTimeMillis(); for (int i = 0; i < numDocuments; i++) { MongoNamespace namespace = namespaces.get(i % NAMESPACES_COUNT); modelList.add(insertOne( @@ -81,7 +79,6 @@ public void before() throws Exception { namespace, Filters.empty())); } - System.out.println("Time to create documents: " + (System.currentTimeMillis() - time)); } @Override diff --git a/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/bulk/MixedCollectionBulkWriteBenchmark.java b/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/bulk/MixedCollectionBulkWriteBenchmark.java index 549ef7ef39c..19a58d89d7c 100644 --- a/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/bulk/MixedCollectionBulkWriteBenchmark.java +++ b/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/bulk/MixedCollectionBulkWriteBenchmark.java @@ -42,13 +42,11 @@ public void before() throws Exception { database.createCollection(COLLECTION_NAME); modelList.clear(); - long time = System.currentTimeMillis(); for (int i = 0; i < numDocuments; i++) { modelList.add(new InsertOneModel<>((createDocument()))); modelList.add(new ReplaceOneModel<>(Filters.empty(), createDocument())); modelList.add(new DeleteOneModel<>(Filters.empty())); } - System.out.println("Time to create models: " + (System.currentTimeMillis() - time)); } @Override From ea3ce0950c8e13ad106efd2d540d6d5d0901a410 Mon Sep 17 00:00:00 2001 From: "slav.babanin" Date: Mon, 24 Mar 2025 20:52:43 -0700 Subject: [PATCH 04/11] Reuse empty filter. JAVA-5545 --- .../benchmark/benchmarks/AbstractWriteBenchmark.java | 3 +++ .../benchmarks/bulk/MixedClientBulkWriteBenchmark.java | 7 ++----- .../benchmarks/bulk/MixedCollectionBulkWriteBenchmark.java | 5 +++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/AbstractWriteBenchmark.java b/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/AbstractWriteBenchmark.java index c7828b1a2df..1ddc0ab5f89 100644 --- a/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/AbstractWriteBenchmark.java +++ b/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/AbstractWriteBenchmark.java @@ -17,13 +17,16 @@ package com.mongodb.benchmark.benchmarks; +import com.mongodb.client.model.Filters; import org.bson.codecs.Codec; import org.bson.codecs.DecoderContext; +import org.bson.conversions.Bson; import org.bson.json.JsonReader; import java.nio.charset.StandardCharsets; public abstract class AbstractWriteBenchmark extends AbstractMongoBenchmark { + protected static final Bson EMPTY_FILTER = Filters.empty(); private final String name; private final String resourcePath; private final Class clazz; diff --git a/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/bulk/MixedClientBulkWriteBenchmark.java b/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/bulk/MixedClientBulkWriteBenchmark.java index d2566166c3d..86fd23c4db0 100644 --- a/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/bulk/MixedClientBulkWriteBenchmark.java +++ b/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/bulk/MixedClientBulkWriteBenchmark.java @@ -21,7 +21,6 @@ import com.mongodb.benchmark.benchmarks.AbstractMongoBenchmark; import com.mongodb.benchmark.benchmarks.AbstractWriteBenchmark; import com.mongodb.client.MongoDatabase; -import com.mongodb.client.model.Filters; import com.mongodb.client.model.bulk.ClientNamespacedWriteModel; import java.util.ArrayList; @@ -72,12 +71,10 @@ public void before() throws Exception { namespace, createDocument())); modelList.add(replaceOne( - namespace, - Filters.empty(), + namespace, EMPTY_FILTER, createDocument())); modelList.add(deleteOne( - namespace, - Filters.empty())); + namespace, EMPTY_FILTER)); } } diff --git a/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/bulk/MixedCollectionBulkWriteBenchmark.java b/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/bulk/MixedCollectionBulkWriteBenchmark.java index 19a58d89d7c..d8b4e2c239b 100644 --- a/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/bulk/MixedCollectionBulkWriteBenchmark.java +++ b/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/bulk/MixedCollectionBulkWriteBenchmark.java @@ -23,6 +23,7 @@ import com.mongodb.client.model.InsertOneModel; import com.mongodb.client.model.ReplaceOneModel; import com.mongodb.client.model.WriteModel; +import org.bson.conversions.Bson; import java.util.ArrayList; import java.util.List; @@ -44,8 +45,8 @@ public void before() throws Exception { modelList.clear(); for (int i = 0; i < numDocuments; i++) { modelList.add(new InsertOneModel<>((createDocument()))); - modelList.add(new ReplaceOneModel<>(Filters.empty(), createDocument())); - modelList.add(new DeleteOneModel<>(Filters.empty())); + modelList.add(new ReplaceOneModel<>(EMPTY_FILTER, createDocument())); + modelList.add(new DeleteOneModel<>(EMPTY_FILTER)); } } From 75c519e62e64afc01c271426c2666f67a08a8bf6 Mon Sep 17 00:00:00 2001 From: "slav.babanin" Date: Tue, 25 Mar 2025 23:19:15 -0700 Subject: [PATCH 05/11] Update server version. JAVA-5545 --- .evergreen/.evg.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.evergreen/.evg.yml b/.evergreen/.evg.yml index 66b809e38a0..3ef4b6126d3 100644 --- a/.evergreen/.evg.yml +++ b/.evergreen/.evg.yml @@ -1552,7 +1552,7 @@ tasks: commands: - func: "bootstrap mongo-orchestration" vars: - VERSION: "v6.0-perf" + VERSION: "v8.0-perf" TOPOLOGY: "server" SSL: "nossl" AUTH: "noauth" From 757fc3bf4eb5d55ddb05bc82c9818ce3cdf78c37 Mon Sep 17 00:00:00 2001 From: "slav.babanin" Date: Wed, 26 Mar 2025 12:28:54 -0700 Subject: [PATCH 06/11] Split perf tests into different tasks. JAVA-5545 --- .evergreen/.evg.yml | 13 +++++++++++++ .../bulk/MixedClientBulkWriteBenchmark.java | 5 ----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/.evergreen/.evg.yml b/.evergreen/.evg.yml index 3ef4b6126d3..5a84f87817f 100644 --- a/.evergreen/.evg.yml +++ b/.evergreen/.evg.yml @@ -1547,8 +1547,20 @@ tasks: product_name: mongo-java-driver - func: "create and upload SSDLC release assets" + #Do not currently rename this task, as we will lose perf timeseries - name: "perf" tags: ["perf"] + commands: + - func: "bootstrap mongo-orchestration" + vars: + VERSION: "v6.0-perf" + TOPOLOGY: "server" + SSL: "nossl" + AUTH: "noauth" + - func: "run perf tests" + - func: "send dashboard data" + - name: "perf-8.0" + tags: [ "perf" ] commands: - func: "bootstrap mongo-orchestration" vars: @@ -2311,6 +2323,7 @@ buildvariants: run_on: rhel90-dbx-perf-large tasks: - name: "perf" + - name: "perf-8.0" - name: plain-auth-test display_name: "PLAIN (LDAP) Auth test" diff --git a/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/bulk/MixedClientBulkWriteBenchmark.java b/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/bulk/MixedClientBulkWriteBenchmark.java index 86fd23c4db0..2d9f1a99dc7 100644 --- a/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/bulk/MixedClientBulkWriteBenchmark.java +++ b/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/bulk/MixedClientBulkWriteBenchmark.java @@ -82,9 +82,4 @@ public void before() throws Exception { public void run() { client.bulkWrite(modelList); } - - @Override - public int getBytesPerRun() { - return 0; - } } From 5e75e447ad7800be5a1dc16886a2bc5f2925f9fb Mon Sep 17 00:00:00 2001 From: Viacheslav Babanin Date: Wed, 26 Mar 2025 14:21:04 -0700 Subject: [PATCH 07/11] Update benchmark file paths and parameters --- .../main/com/mongodb/benchmark/benchmarks/BenchmarkSuite.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/BenchmarkSuite.java b/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/BenchmarkSuite.java index 9d432e7c7e9..b3d4dc31fb7 100644 --- a/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/BenchmarkSuite.java +++ b/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/BenchmarkSuite.java @@ -97,7 +97,7 @@ private static void runBenchmarks() runBenchmark(new MixedCollectionBulkWriteBenchmark<>("./single_and_multi_document/small_doc.json", 10_000, DOCUMENT_CLASS)); - runBenchmark(new MixedClientBulkWriteBenchmark<>("./single_and_multi_document/large_doc.json", 10, + runBenchmark(new MixedClientBulkWriteBenchmark<>("./single_and_multi_document/small_doc.json", 10_000, DOCUMENT_CLASS)); runBenchmark(new GridFSUploadBenchmark("single_and_multi_document/gridfs_large.bin")); From a09f89db0b71c6174aba86372030208844988bbb Mon Sep 17 00:00:00 2001 From: "slav.babanin" Date: Wed, 26 Mar 2025 22:11:14 -0700 Subject: [PATCH 08/11] Remove version 6 perf tests. JAVA-5545 --- .evergreen/.evg.yml | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/.evergreen/.evg.yml b/.evergreen/.evg.yml index 5a84f87817f..70fd2fbb870 100644 --- a/.evergreen/.evg.yml +++ b/.evergreen/.evg.yml @@ -1547,20 +1547,9 @@ tasks: product_name: mongo-java-driver - func: "create and upload SSDLC release assets" - #Do not currently rename this task, as we will lose perf timeseries + #Do not rename this task, as we will lose perf timeseries - name: "perf" tags: ["perf"] - commands: - - func: "bootstrap mongo-orchestration" - vars: - VERSION: "v6.0-perf" - TOPOLOGY: "server" - SSL: "nossl" - AUTH: "noauth" - - func: "run perf tests" - - func: "send dashboard data" - - name: "perf-8.0" - tags: [ "perf" ] commands: - func: "bootstrap mongo-orchestration" vars: @@ -2323,7 +2312,6 @@ buildvariants: run_on: rhel90-dbx-perf-large tasks: - name: "perf" - - name: "perf-8.0" - name: plain-auth-test display_name: "PLAIN (LDAP) Auth test" From ebc56b3127662dc7ab2f5f0942949956dcffab8c Mon Sep 17 00:00:00 2001 From: "slav.babanin" Date: Wed, 26 Mar 2025 22:18:20 -0700 Subject: [PATCH 09/11] Correct comment. JAVA-5545 --- .evergreen/.evg.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.evergreen/.evg.yml b/.evergreen/.evg.yml index 70fd2fbb870..2cd25fa4a32 100644 --- a/.evergreen/.evg.yml +++ b/.evergreen/.evg.yml @@ -1547,7 +1547,7 @@ tasks: product_name: mongo-java-driver - func: "create and upload SSDLC release assets" - #Do not rename this task, as we will lose perf timeseries + # Do not rename this task – renaming resets the performance time series - name: "perf" tags: ["perf"] commands: From 48b7a999118d5be33d6d99b55be715bda43c1946 Mon Sep 17 00:00:00 2001 From: "slav.babanin" Date: Thu, 27 Mar 2025 18:26:21 -0700 Subject: [PATCH 10/11] Fix dataset size. JAVA-5545 --- .../benchmark/benchmarks/AbstractWriteBenchmark.java | 8 ++++---- .../benchmarks/bulk/MixedClientBulkWriteBenchmark.java | 2 +- .../bulk/MixedCollectionBulkWriteBenchmark.java | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/AbstractWriteBenchmark.java b/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/AbstractWriteBenchmark.java index 1ddc0ab5f89..c4c0e4a5bac 100644 --- a/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/AbstractWriteBenchmark.java +++ b/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/AbstractWriteBenchmark.java @@ -33,18 +33,18 @@ public abstract class AbstractWriteBenchmark extends AbstractMongoBenchmark { private byte[] bytes; protected int fileLength; protected T document; - protected int numIterations; + protected int numInternalIterations; protected int numDocuments; protected AbstractWriteBenchmark(final String name, final String resourcePath, - int numIterations, + int numInternalIterations, int numDocuments, final Class clazz) { this.name = name; this.resourcePath = resourcePath; this.clazz = clazz; - this.numIterations = numIterations; + this.numInternalIterations = numInternalIterations; this.numDocuments = numDocuments; } @@ -69,6 +69,6 @@ protected T createDocument() { @Override public int getBytesPerRun() { - return fileLength * numIterations * numDocuments; + return fileLength * numInternalIterations * numDocuments; } } diff --git a/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/bulk/MixedClientBulkWriteBenchmark.java b/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/bulk/MixedClientBulkWriteBenchmark.java index 2d9f1a99dc7..a4a8d046a05 100644 --- a/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/bulk/MixedClientBulkWriteBenchmark.java +++ b/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/bulk/MixedClientBulkWriteBenchmark.java @@ -37,7 +37,7 @@ public class MixedClientBulkWriteBenchmark extends AbstractWriteBenchmark private List namespaces; public MixedClientBulkWriteBenchmark(final String resourcePath, final int numDocuments, final Class clazz) { - super("Small doc Client BulkWrite Mixed Operations", resourcePath, 1, numDocuments * 3, clazz); + super("Small doc Client BulkWrite Mixed Operations", resourcePath, 1, numDocuments * 2, clazz); modelList = new ArrayList<>(super.numDocuments); namespaces = new ArrayList<>(NAMESPACES_COUNT); } diff --git a/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/bulk/MixedCollectionBulkWriteBenchmark.java b/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/bulk/MixedCollectionBulkWriteBenchmark.java index d8b4e2c239b..3abdb88dba7 100644 --- a/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/bulk/MixedCollectionBulkWriteBenchmark.java +++ b/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/bulk/MixedCollectionBulkWriteBenchmark.java @@ -32,7 +32,7 @@ public class MixedCollectionBulkWriteBenchmark extends AbstractCollectionWrit private final List> modelList; public MixedCollectionBulkWriteBenchmark(final String resourcePath, final int numDocuments, final Class clazz) { - super("Small doc Collection BulkWrite Mixed Operations", resourcePath, 1, numDocuments * 3, clazz); + super("Small doc Collection BulkWrite Mixed Operations", resourcePath, 1, numDocuments * 2, clazz); modelList = new ArrayList<>(super.numDocuments); } From 411088a574fab625b08012b7ed8ae87019d22217 Mon Sep 17 00:00:00 2001 From: "slav.babanin" Date: Fri, 28 Mar 2025 10:40:09 -0700 Subject: [PATCH 11/11] Change modelList size. JAVA-5545 --- .../benchmarks/AbstractCollectionWriteBenchmark.java | 4 ++-- .../benchmarks/bulk/MixedClientBulkWriteBenchmark.java | 7 ++++--- .../benchmarks/bulk/MixedCollectionBulkWriteBenchmark.java | 7 +++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/AbstractCollectionWriteBenchmark.java b/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/AbstractCollectionWriteBenchmark.java index 867f20cd84c..38a4b1104b5 100644 --- a/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/AbstractCollectionWriteBenchmark.java +++ b/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/AbstractCollectionWriteBenchmark.java @@ -31,9 +31,9 @@ public abstract class AbstractCollectionWriteBenchmark extends AbstractWriteB protected AbstractCollectionWriteBenchmark(final String name, final String resourcePath, int numIterations, - int numberDocuments, + int numDocuments, final Class clazz) { - super(name, resourcePath, numIterations, numberDocuments, clazz); + super(name, resourcePath, numIterations, numDocuments, clazz); this.name = name; this.clazz = clazz; } diff --git a/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/bulk/MixedClientBulkWriteBenchmark.java b/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/bulk/MixedClientBulkWriteBenchmark.java index a4a8d046a05..7c23712cce7 100644 --- a/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/bulk/MixedClientBulkWriteBenchmark.java +++ b/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/bulk/MixedClientBulkWriteBenchmark.java @@ -37,9 +37,10 @@ public class MixedClientBulkWriteBenchmark extends AbstractWriteBenchmark private List namespaces; public MixedClientBulkWriteBenchmark(final String resourcePath, final int numDocuments, final Class clazz) { + // numDocuments * 2 aligns with bytes transferred (insertOne + replaceOne documents) super("Small doc Client BulkWrite Mixed Operations", resourcePath, 1, numDocuments * 2, clazz); - modelList = new ArrayList<>(super.numDocuments); - namespaces = new ArrayList<>(NAMESPACES_COUNT); + this.modelList = new ArrayList<>(numDocuments * 3); + this.namespaces = new ArrayList<>(NAMESPACES_COUNT); } @Override @@ -65,7 +66,7 @@ public void before() throws Exception { } modelList.clear(); - for (int i = 0; i < numDocuments; i++) { + for (int i = 0; i < numDocuments / 2; i++) { MongoNamespace namespace = namespaces.get(i % NAMESPACES_COUNT); modelList.add(insertOne( namespace, diff --git a/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/bulk/MixedCollectionBulkWriteBenchmark.java b/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/bulk/MixedCollectionBulkWriteBenchmark.java index 3abdb88dba7..84bf29e0d2e 100644 --- a/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/bulk/MixedCollectionBulkWriteBenchmark.java +++ b/driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/bulk/MixedCollectionBulkWriteBenchmark.java @@ -19,11 +19,9 @@ import com.mongodb.benchmark.benchmarks.AbstractCollectionWriteBenchmark; import com.mongodb.client.model.DeleteOneModel; -import com.mongodb.client.model.Filters; import com.mongodb.client.model.InsertOneModel; import com.mongodb.client.model.ReplaceOneModel; import com.mongodb.client.model.WriteModel; -import org.bson.conversions.Bson; import java.util.ArrayList; import java.util.List; @@ -32,8 +30,9 @@ public class MixedCollectionBulkWriteBenchmark extends AbstractCollectionWrit private final List> modelList; public MixedCollectionBulkWriteBenchmark(final String resourcePath, final int numDocuments, final Class clazz) { + // numDocuments * 2 aligns with bytes transferred (insertOne + replaceOne documents) super("Small doc Collection BulkWrite Mixed Operations", resourcePath, 1, numDocuments * 2, clazz); - modelList = new ArrayList<>(super.numDocuments); + this.modelList = new ArrayList<>(numDocuments * 3); } @@ -43,7 +42,7 @@ public void before() throws Exception { database.createCollection(COLLECTION_NAME); modelList.clear(); - for (int i = 0; i < numDocuments; i++) { + for (int i = 0; i < numDocuments / 2; i++) { modelList.add(new InsertOneModel<>((createDocument()))); modelList.add(new ReplaceOneModel<>(EMPTY_FILTER, createDocument())); modelList.add(new DeleteOneModel<>(EMPTY_FILTER));