Skip to content

Commit 1aad7bd

Browse files
committed
Merge branch 'main' into JAVA-5813
# Conflicts: # driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/AbstractMongoBenchmark.java # driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/AbstractWriteBenchmark.java
2 parents eeaf99d + e1eb156 commit 1aad7bd

11 files changed

+351
-46
lines changed

.evergreen/.evg.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1549,12 +1549,13 @@ tasks:
15491549
product_name: mongo-java-driver
15501550
- func: "create and upload SSDLC release assets"
15511551

1552+
# Do not rename this task – renaming resets the performance time series
15521553
- name: "perf"
15531554
tags: ["perf"]
15541555
commands:
15551556
- func: "bootstrap mongo-orchestration"
15561557
vars:
1557-
VERSION: "v6.0-perf"
1558+
VERSION: "v8.0-perf"
15581559
TOPOLOGY: "server"
15591560
SSL: "nossl"
15601561
AUTH: "noauth"
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright 2016-present MongoDB, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
package com.mongodb.benchmark.benchmarks;
19+
20+
import com.mongodb.client.MongoCollection;
21+
import com.mongodb.client.MongoDatabase;
22+
23+
public abstract class AbstractCollectionWriteBenchmark<T> extends AbstractWriteBenchmark<T> {
24+
25+
protected MongoCollection<T> collection;
26+
protected MongoDatabase database;
27+
28+
private final String name;
29+
private final Class<T> clazz;
30+
31+
protected AbstractCollectionWriteBenchmark(final String name,
32+
final String resourcePath,
33+
int numIterations,
34+
int numDocuments,
35+
final Class<T> clazz) {
36+
super(name, resourcePath, numIterations, numDocuments, clazz);
37+
this.name = name;
38+
this.clazz = clazz;
39+
}
40+
41+
@Override
42+
public void setUp() throws Exception {
43+
super.setUp();
44+
database = client.getDatabase(DATABASE_NAME);
45+
collection = database.getCollection(COLLECTION_NAME, clazz);
46+
database.drop();
47+
}
48+
49+
@Override
50+
public void before() throws Exception {
51+
super.before();
52+
collection.drop();
53+
}
54+
55+
@Override
56+
public String getName() {
57+
return name;
58+
}
59+
}

driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/AbstractMongoBenchmark.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package com.mongodb.benchmark.benchmarks;
1919

2020
import com.mongodb.MongoClientSettings;
21+
import com.mongodb.MongoNamespace;
2122
import com.mongodb.benchmark.framework.Benchmark;
2223
import com.mongodb.client.MongoClient;
2324
import com.mongodb.client.MongoClients;
@@ -34,6 +35,8 @@ public abstract class AbstractMongoBenchmark extends Benchmark {
3435

3536
protected static final String DATABASE_NAME = "perftest";
3637
protected static final String COLLECTION_NAME = "corpus";
38+
protected static final MongoNamespace NAMESPACE = new MongoNamespace(
39+
AbstractMongoBenchmark.DATABASE_NAME, AbstractMongoBenchmark.COLLECTION_NAME);
3740
protected MongoClientSettings mongoClientSettings;
3841

3942
public AbstractMongoBenchmark(final String name) {

driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/AbstractInsertBenchmark.java renamed to driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/AbstractWriteBenchmark.java

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
7-
*
7+
*
88
* http://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
@@ -17,56 +17,52 @@
1717

1818
package com.mongodb.benchmark.benchmarks;
1919

20-
import com.mongodb.client.MongoCollection;
21-
import com.mongodb.client.MongoDatabase;
20+
import com.mongodb.client.model.Filters;
2221
import org.bson.codecs.Codec;
2322
import org.bson.codecs.DecoderContext;
23+
import org.bson.conversions.Bson;
2424
import org.bson.json.JsonReader;
2525

2626
import java.nio.charset.StandardCharsets;
2727

28-
public abstract class AbstractInsertBenchmark<T> extends AbstractMongoBenchmark {
29-
30-
protected MongoCollection<T> collection;
31-
28+
public abstract class AbstractWriteBenchmark<T> extends AbstractMongoBenchmark {
29+
protected static final Bson EMPTY_FILTER = Filters.empty();
3230
private final String resourcePath;
3331
private final Class<T> clazz;
3432
private byte[] bytes;
3533
protected int fileLength;
3634
protected T document;
37-
38-
protected AbstractInsertBenchmark(final String name, final String resourcePath, final Class<T> clazz) {
35+
protected int numInternalIterations;
36+
protected int numDocuments;
37+
38+
protected AbstractWriteBenchmark(final String name,
39+
final String resourcePath,
40+
int numInternalIterations,
41+
int numDocuments,
42+
final Class<T> clazz) {
3943
super(name);
4044
this.resourcePath = resourcePath;
4145
this.clazz = clazz;
46+
this.numInternalIterations = numInternalIterations;
47+
this.numDocuments = numDocuments;
4248
}
4349

4450
@Override
4551
public void setUp() throws Exception {
4652
super.setUp();
47-
MongoDatabase database = client.getDatabase(DATABASE_NAME);
48-
49-
collection = database.getCollection(COLLECTION_NAME, clazz);
50-
51-
database.drop();
5253
bytes = readAllBytesFromRelativePath(resourcePath);
53-
5454
fileLength = bytes.length;
55-
56-
Codec<T> codec = collection.getCodecRegistry().get(clazz);
57-
55+
Codec<T> codec = client.getCodecRegistry().get(clazz);
5856
document = codec.decode(new JsonReader(new String(bytes, StandardCharsets.UTF_8)), DecoderContext.builder().build());
5957
}
6058

61-
@Override
62-
public void before() throws Exception {
63-
super.before();
64-
collection.drop();
65-
}
66-
6759
protected T createDocument() {
68-
Codec<T> codec = collection.getCodecRegistry().get(clazz);
69-
60+
Codec<T> codec = client.getCodecRegistry().get(clazz);
7061
return codec.decode(new JsonReader(new String(bytes, StandardCharsets.UTF_8)), DecoderContext.builder().build());
7162
}
63+
64+
@Override
65+
public int getBytesPerRun() {
66+
return fileLength * numInternalIterations * numDocuments;
67+
}
7268
}

driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/BenchmarkSuite.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717

1818
package com.mongodb.benchmark.benchmarks;
1919

20+
import com.mongodb.benchmark.benchmarks.bulk.ClientBulkWriteBenchmark;
21+
import com.mongodb.benchmark.benchmarks.bulk.CollectionBulkWriteBenchmark;
22+
import com.mongodb.benchmark.benchmarks.bulk.MixedClientBulkWriteBenchmark;
23+
import com.mongodb.benchmark.benchmarks.bulk.MixedCollectionBulkWriteBenchmark;
2024
import com.mongodb.benchmark.framework.Benchmark;
2125
import com.mongodb.benchmark.framework.BenchmarkResult;
2226
import com.mongodb.benchmark.framework.BenchmarkResultWriter;
@@ -70,17 +74,32 @@ private static void runBenchmarks()
7074
runBenchmark(new RunCommandBenchmark<>(DOCUMENT_CODEC));
7175
runBenchmark(new FindOneBenchmark<Document>("single_and_multi_document/tweet.json", BenchmarkSuite.DOCUMENT_CLASS));
7276

73-
runBenchmark(new InsertOneBenchmark<Document>("Small", "./single_and_multi_document/small_doc.json", 10000,
77+
runBenchmark(new InsertOneBenchmark<Document>("Small", "./single_and_multi_document/small_doc.json", 10_000,
7478
DOCUMENT_CLASS, ID_REMOVER));
7579
runBenchmark(new InsertOneBenchmark<Document>("Large", "./single_and_multi_document/large_doc.json", 10,
7680
DOCUMENT_CLASS, ID_REMOVER));
7781

7882
runBenchmark(new FindManyBenchmark<Document>("single_and_multi_document/tweet.json", BenchmarkSuite.DOCUMENT_CLASS));
79-
runBenchmark(new InsertManyBenchmark<Document>("Small", "./single_and_multi_document/small_doc.json", 10000,
83+
runBenchmark(new InsertManyBenchmark<Document>("Small", "./single_and_multi_document/small_doc.json", 10_000,
8084
DOCUMENT_CLASS));
8185
runBenchmark(new InsertManyBenchmark<Document>("Large", "./single_and_multi_document/large_doc.json", 10,
8286
DOCUMENT_CLASS));
8387

88+
runBenchmark(new CollectionBulkWriteBenchmark<>("Small", "./single_and_multi_document/small_doc.json", 10_000,
89+
DOCUMENT_CLASS));
90+
runBenchmark(new CollectionBulkWriteBenchmark<>("Large", "./single_and_multi_document/large_doc.json", 10,
91+
DOCUMENT_CLASS));
92+
93+
runBenchmark(new ClientBulkWriteBenchmark<>("Small", "./single_and_multi_document/small_doc.json", 10_000,
94+
DOCUMENT_CLASS));
95+
runBenchmark(new ClientBulkWriteBenchmark<>("Large", "./single_and_multi_document/large_doc.json", 10,
96+
DOCUMENT_CLASS));
97+
98+
runBenchmark(new MixedCollectionBulkWriteBenchmark<>("./single_and_multi_document/small_doc.json", 10_000,
99+
DOCUMENT_CLASS));
100+
runBenchmark(new MixedClientBulkWriteBenchmark<>("./single_and_multi_document/small_doc.json", 10_000,
101+
DOCUMENT_CLASS));
102+
84103
runBenchmark(new GridFSUploadBenchmark("single_and_multi_document/gridfs_large.bin"));
85104
runBenchmark(new GridFSDownloadBenchmark("single_and_multi_document/gridfs_large.bin"));
86105

driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/InsertManyBenchmark.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,11 @@
2020
import java.util.ArrayList;
2121
import java.util.List;
2222

23-
public class InsertManyBenchmark<T> extends AbstractInsertBenchmark<T> {
24-
private final int numDocuments;
23+
public class InsertManyBenchmark<T> extends AbstractCollectionWriteBenchmark<T> {
2524
private final List<T> documentList;
2625

2726
public InsertManyBenchmark(final String name, final String resourcePath, final int numDocuments, final Class<T> clazz) {
28-
super(name + " doc bulk insert", resourcePath, clazz);
29-
this.numDocuments = numDocuments;
27+
super(name + " doc bulk insert", resourcePath, 1, numDocuments, clazz);
3028
documentList = new ArrayList<>(numDocuments);
3129
}
3230

@@ -48,9 +46,4 @@ public void before() throws Exception {
4846
public void run() {
4947
collection.insertMany(documentList);
5048
}
51-
52-
@Override
53-
public int getBytesPerRun() {
54-
return fileLength * numDocuments;
55-
}
5649
}

driver-benchmarks/src/main/com/mongodb/benchmark/benchmarks/InsertOneBenchmark.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717

1818
package com.mongodb.benchmark.benchmarks;
1919

20-
public class InsertOneBenchmark<T> extends AbstractInsertBenchmark<T> {
20+
public class InsertOneBenchmark<T> extends AbstractCollectionWriteBenchmark<T> {
2121
private final int numIterations;
2222
private final IdRemover<T> idRemover;
2323

2424
public InsertOneBenchmark(final String name, final String resourcePath, final int numIterations, final Class<T> clazz,
2525
final IdRemover<T> idRemover) {
26-
super(name + " doc insertOne", resourcePath, clazz);
26+
super(name + " doc insertOne", resourcePath, numIterations, 1, clazz);
2727
this.numIterations = numIterations;
2828
this.idRemover = idRemover;
2929
}
@@ -35,10 +35,4 @@ public void run() {
3535
collection.insertOne(document);
3636
}
3737
}
38-
39-
@Override
40-
public int getBytesPerRun() {
41-
return fileLength * numIterations;
42-
}
43-
4438
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright 2016-present MongoDB, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
package com.mongodb.benchmark.benchmarks.bulk;
19+
20+
import com.mongodb.benchmark.benchmarks.AbstractCollectionWriteBenchmark;
21+
import com.mongodb.client.model.bulk.ClientNamespacedInsertOneModel;
22+
import com.mongodb.client.model.bulk.ClientNamespacedWriteModel;
23+
24+
import java.util.ArrayList;
25+
import java.util.List;
26+
27+
public class ClientBulkWriteBenchmark<T> extends AbstractCollectionWriteBenchmark<T> {
28+
private final List<ClientNamespacedInsertOneModel> modelList;
29+
30+
public ClientBulkWriteBenchmark(final String name, final String resourcePath, final int numDocuments, final Class<T> clazz) {
31+
super(name + " doc Client BulkWrite insert", resourcePath, 1, numDocuments, clazz);
32+
modelList = new ArrayList<>(numDocuments);
33+
}
34+
35+
@Override
36+
public void before() throws Exception {
37+
super.before();
38+
database.createCollection(COLLECTION_NAME);
39+
40+
modelList.clear();
41+
for (int i = 0; i < numDocuments; i++) {
42+
modelList.add(ClientNamespacedWriteModel.insertOne(NAMESPACE, createDocument()));
43+
}
44+
}
45+
46+
@Override
47+
public void run() {
48+
client.bulkWrite(modelList);
49+
}
50+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright 2016-present MongoDB, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
package com.mongodb.benchmark.benchmarks.bulk;
19+
20+
import com.mongodb.benchmark.benchmarks.AbstractCollectionWriteBenchmark;
21+
import com.mongodb.client.model.InsertOneModel;
22+
23+
import java.util.ArrayList;
24+
import java.util.List;
25+
26+
public class CollectionBulkWriteBenchmark<T> extends AbstractCollectionWriteBenchmark<T> {
27+
private final List<InsertOneModel<T>> modelList;
28+
29+
public CollectionBulkWriteBenchmark(final String name, final String resourcePath, final int numDocuments, final Class<T> clazz) {
30+
super(name + " doc Collection BulkWrite insert", resourcePath, 1, numDocuments, clazz);
31+
modelList = new ArrayList<>(numDocuments);
32+
}
33+
34+
@Override
35+
public void before() throws Exception {
36+
super.before();
37+
database.createCollection(COLLECTION_NAME);
38+
modelList.clear();
39+
for (int i = 0; i < numDocuments; i++) {
40+
modelList.add(new InsertOneModel<>((createDocument())));
41+
}
42+
}
43+
44+
@Override
45+
public void run() {
46+
collection.bulkWrite(modelList);
47+
}
48+
}

0 commit comments

Comments
 (0)