Skip to content

Commit 729601a

Browse files
committed
CSHARP-5203: Benchmark Collection and Client bulkWrite
1 parent 38cd6df commit 729601a

File tree

7 files changed

+134
-13
lines changed

7 files changed

+134
-13
lines changed

benchmarks/MongoDB.Driver.Benchmarks/BenchmarkResult.cs

+7-4
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,24 @@ public sealed class BenchmarkResult
2727

2828
public BenchmarkResult(BenchmarkReport benchmarkReport)
2929
{
30+
Categories = new HashSet<string>(benchmarkReport.BenchmarkCase.Descriptor.Categories);
31+
3032
int dataSetSize;
31-
if (benchmarkReport.BenchmarkCase.Descriptor.HasCategory(DriverBenchmarkCategory.BsonBench))
33+
if (Categories.Contains(DriverBenchmarkCategory.BsonBench))
3234
{
3335
var bsonBenchmarkData = (BsonBenchmarkData)benchmarkReport.BenchmarkCase.Parameters["BenchmarkData"];
3436
Name = bsonBenchmarkData.DataSetName + benchmarkReport.BenchmarkCase.Descriptor.Type.Name;
3537
dataSetSize = bsonBenchmarkData.DataSetSize;
3638
}
3739
else
3840
{
39-
Name = benchmarkReport.BenchmarkCase.Descriptor.Type.Name;
41+
Name = Categories.Contains(DriverBenchmarkCategory.BulkWriteBench)
42+
? benchmarkReport.BenchmarkCase.Descriptor.WorkloadMethod.Name
43+
: benchmarkReport.BenchmarkCase.Descriptor.Type.Name;
44+
4045
dataSetSize = (int)benchmarkReport.BenchmarkCase.Parameters["BenchmarkDataSetSize"];
4146
}
4247

43-
Categories = new HashSet<string>(benchmarkReport.BenchmarkCase.Descriptor.Categories);
44-
4548
// change the median from nanoseconds to seconds for calculating the score.
4649
// since dataSetSize is in bytes, divide the score to convert to MB/s
4750
Score = (dataSetSize / (benchmarkReport.ResultStatistics.Median / 1_000_000_000D)) / 1_000_000D;

benchmarks/MongoDB.Driver.Benchmarks/DriverBenchmarkCategory.cs

+3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ public static class DriverBenchmarkCategory
2626
public const string ReadBench = "ReadBench";
2727
public const string SingleBench = "SingleBench";
2828
public const string WriteBench = "WriteBench";
29+
30+
// not included in AllCategories as it's not part of the benchmarking spec
31+
public const string BulkWriteBench = "BulkWriteBench";
2932

3033
public static readonly IEnumerable<string> AllCategories = new[] {BsonBench, ReadBench, WriteBench, MultiBench, SingleBench, ParallelBench, DriverBench};
3134
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/* Copyright 2010-present MongoDB Inc.
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
using System.Collections.Generic;
17+
using BenchmarkDotNet.Attributes;
18+
using MongoDB.Bson;
19+
using MongoDB.Driver;
20+
using static MongoDB.Benchmarks.BenchmarkHelper;
21+
22+
namespace MongoDB.Benchmarks.MultiDoc
23+
{
24+
[IterationCount(100)]
25+
[BenchmarkCategory(DriverBenchmarkCategory.BulkWriteBench, DriverBenchmarkCategory.MultiBench, DriverBenchmarkCategory.WriteBench, DriverBenchmarkCategory.DriverBench)]
26+
public class BulkWriteMixedOpsBenchmark
27+
{
28+
private IMongoClient _client;
29+
private IMongoCollection<BsonDocument> _collection;
30+
private IMongoDatabase _database;
31+
private readonly List<BulkWriteModel> _clientBulkWriteMixedOpsModels = [];
32+
private readonly List<WriteModel<BsonDocument>> _collectionBulkWriteMixedOpsModels = [];
33+
34+
private static readonly CollectionNamespace __collectionNamespace =
35+
CollectionNamespace.FromFullName($"{MongoConfiguration.PerfTestDatabaseName}.{MongoConfiguration.PerfTestCollectionName}");
36+
37+
[Params(5_500_000)]
38+
public int BenchmarkDataSetSize { get; set; } // used in BenchmarkResult.cs
39+
40+
[GlobalSetup]
41+
public void Setup()
42+
{
43+
_client = MongoConfiguration.CreateClient();
44+
_database = _client.GetDatabase(MongoConfiguration.PerfTestDatabaseName);
45+
46+
var smallDocument = ReadExtendedJson("single_and_multi_document/small_doc.json");
47+
for (var i = 0; i < 10000; i++)
48+
{
49+
_clientBulkWriteMixedOpsModels.Add(new BulkWriteInsertOneModel<BsonDocument>(__collectionNamespace, smallDocument.DeepClone().AsBsonDocument));
50+
_clientBulkWriteMixedOpsModels.Add(new BulkWriteReplaceOneModel<BsonDocument>(__collectionNamespace, FilterDefinition<BsonDocument>.Empty, smallDocument.DeepClone().AsBsonDocument));
51+
_clientBulkWriteMixedOpsModels.Add(new BulkWriteDeleteOneModel<BsonDocument>(__collectionNamespace, FilterDefinition<BsonDocument>.Empty));
52+
53+
_collectionBulkWriteMixedOpsModels.Add(new InsertOneModel<BsonDocument>(smallDocument.DeepClone().AsBsonDocument));
54+
_collectionBulkWriteMixedOpsModels.Add(new ReplaceOneModel<BsonDocument>(FilterDefinition<BsonDocument>.Empty, smallDocument.DeepClone().AsBsonDocument));
55+
_collectionBulkWriteMixedOpsModels.Add(new DeleteOneModel<BsonDocument>(FilterDefinition<BsonDocument>.Empty));
56+
}
57+
}
58+
59+
[IterationSetup]
60+
public void BeforeTask()
61+
{
62+
_database.DropCollection(MongoConfiguration.PerfTestCollectionName);
63+
_collection = _database.GetCollection<BsonDocument>(MongoConfiguration.PerfTestCollectionName);
64+
}
65+
66+
[Benchmark]
67+
public void SmallDocCollectionBulkMixedOpsBenchmark()
68+
{
69+
_collection.BulkWrite(_collectionBulkWriteMixedOpsModels, new BulkWriteOptions());
70+
}
71+
72+
[Benchmark]
73+
public void SmallDocClientBulkMixedOpsBenchmark()
74+
{
75+
_client.BulkWrite(_clientBulkWriteMixedOpsModels, new ClientBulkWriteOptions());
76+
}
77+
78+
[GlobalCleanup]
79+
public void Teardown()
80+
{
81+
_client.Dispose();
82+
}
83+
}
84+
}

benchmarks/MongoDB.Driver.Benchmarks/MultiDoc/InsertManyLargeBenchmark.cs renamed to benchmarks/MongoDB.Driver.Benchmarks/MultiDoc/LargeDocBulkInsertBenchmark.cs

+13-4
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,21 @@
1818
using BenchmarkDotNet.Attributes;
1919
using MongoDB.Bson;
2020
using MongoDB.Driver;
21-
using MongoDB.Driver.TestHelpers;
2221
using static MongoDB.Benchmarks.BenchmarkHelper;
2322

2423
namespace MongoDB.Benchmarks.MultiDoc
2524
{
2625
[IterationCount(100)]
27-
[BenchmarkCategory(DriverBenchmarkCategory.MultiBench, DriverBenchmarkCategory.WriteBench, DriverBenchmarkCategory.DriverBench)]
28-
public class InsertManyLargeBenchmark
26+
[BenchmarkCategory(DriverBenchmarkCategory.BulkWriteBench, DriverBenchmarkCategory.MultiBench, DriverBenchmarkCategory.WriteBench, DriverBenchmarkCategory.DriverBench)]
27+
public class LargeDocBulkInsertBenchmark
2928
{
3029
private IMongoClient _client;
3130
private IMongoCollection<BsonDocument> _collection;
3231
private IMongoDatabase _database;
3332
private IEnumerable<BsonDocument> _largeDocuments;
33+
34+
private static readonly CollectionNamespace __collectionNamespace =
35+
CollectionNamespace.FromFullName($"{MongoConfiguration.PerfTestDatabaseName}.{MongoConfiguration.PerfTestCollectionName}");
3436

3537
[Params(27_310_890)]
3638
public int BenchmarkDataSetSize { get; set; } // used in BenchmarkResult.cs
@@ -53,10 +55,17 @@ public void BeforeTask()
5355
}
5456

5557
[Benchmark]
56-
public void InsertManyLarge()
58+
public void InsertManyLargeBenchmark()
5759
{
5860
_collection.InsertMany(_largeDocuments, new InsertManyOptions());
5961
}
62+
63+
[Benchmark]
64+
public void LargeDocClientBulkInsertBenchmark()
65+
{
66+
var models = _largeDocuments.Select(x => new BulkWriteInsertOneModel<BsonDocument>(__collectionNamespace, x)).ToList();
67+
_client.BulkWrite(models, new ClientBulkWriteOptions());
68+
}
6069

6170
[GlobalCleanup]
6271
public void Teardown()

benchmarks/MongoDB.Driver.Benchmarks/MultiDoc/InsertManySmallBenchmark.cs renamed to benchmarks/MongoDB.Driver.Benchmarks/MultiDoc/SmallDocBulkInsertBenchmark.cs

+13-4
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,22 @@
1818
using BenchmarkDotNet.Attributes;
1919
using MongoDB.Bson;
2020
using MongoDB.Driver;
21-
using MongoDB.Driver.TestHelpers;
2221
using static MongoDB.Benchmarks.BenchmarkHelper;
2322

2423
namespace MongoDB.Benchmarks.MultiDoc
2524
{
2625
[IterationCount(100)]
27-
[BenchmarkCategory(DriverBenchmarkCategory.MultiBench, DriverBenchmarkCategory.WriteBench, DriverBenchmarkCategory.DriverBench)]
28-
public class InsertManySmallBenchmark
26+
[BenchmarkCategory(DriverBenchmarkCategory.BulkWriteBench, DriverBenchmarkCategory.MultiBench, DriverBenchmarkCategory.WriteBench, DriverBenchmarkCategory.DriverBench)]
27+
public class SmallDocBulkInsertBenchmark
2928
{
3029
private IMongoClient _client;
3130
private IMongoCollection<BsonDocument> _collection;
3231
private IMongoDatabase _database;
3332
private IEnumerable<BsonDocument> _smallDocuments;
3433

34+
private static readonly CollectionNamespace __collectionNamespace =
35+
CollectionNamespace.FromFullName($"{MongoConfiguration.PerfTestDatabaseName}.{MongoConfiguration.PerfTestCollectionName}");
36+
3537
[Params(2_750_000)]
3638
public int BenchmarkDataSetSize { get; set; } // used in BenchmarkResult.cs
3739

@@ -53,10 +55,17 @@ public void BeforeTask()
5355
}
5456

5557
[Benchmark]
56-
public void InsertManySmall()
58+
public void InsertManySmallBenchmark()
5759
{
5860
_collection.InsertMany(_smallDocuments, new InsertManyOptions());
5961
}
62+
63+
[Benchmark]
64+
public void SmallDocClientBulkInsertBenchmark()
65+
{
66+
var models = _smallDocuments.Select(x => new BulkWriteInsertOneModel<BsonDocument>(__collectionNamespace, x)).ToList();
67+
_client.BulkWrite(models, new ClientBulkWriteOptions());
68+
}
6069

6170
[GlobalCleanup]
6271
public void Teardown()

benchmarks/MongoDB.Driver.Benchmarks/scripts/download-data.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/sh
1+
#!/usr/bin/env bash
22

33
# Copyright 2010 MongoDB, Inc.
44
#

evergreen/evergreen.yml

+13
Original file line numberDiff line numberDiff line change
@@ -1570,6 +1570,18 @@ tasks:
15701570
- func: install-dotnet
15711571
- func: run-performance-tests
15721572

1573+
- name: performance-tests-net80-server-v8.0
1574+
commands:
1575+
- func: bootstrap-mongo-orchestration
1576+
vars:
1577+
VERSION: "v8.0-perf"
1578+
TOPOLOGY: "server"
1579+
SSL: "nossl"
1580+
AUTH: "noauth"
1581+
SKIP_LEGACY_SHELL: "true"
1582+
- func: install-dotnet
1583+
- func: run-performance-tests
1584+
15731585
- name: test-aws-lambda-deployed
15741586
commands:
15751587
- command: ec2.assume_role
@@ -2635,6 +2647,7 @@ buildvariants:
26352647
- rhel90-dbx-perf-large
26362648
tasks:
26372649
- name: performance-tests-net80-server-v6.0
2650+
- name: performance-tests-net80-server-v8.0
26382651

26392652
# AWS Lambda tests
26402653
- name: aws-lambda-tests

0 commit comments

Comments
 (0)