Skip to content

Commit 49446fe

Browse files
Adding perf improvements ofr ObjectNode mapping (Azure#18859)
1 parent 634c5c8 commit 49446fe

File tree

20 files changed

+265
-34
lines changed

20 files changed

+265
-34
lines changed

sdk/cosmos/azure-cosmos-dotnet-benchmark/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ Copyright (C) 2019 CosmosBenchmark
6363
6464
--partitionKeyPath Container partition key path
6565
66-
-pl Degree of parallism
66+
-pl Degree of parallism
67+
68+
-w Workload name
6769
6870
--itemTemplateFile Item template
6971

sdk/cosmos/azure-cosmos-dotnet-benchmark/pom.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,19 @@ Licensed under the MIT License.
8080
<version>4.13.1</version> <!-- {x-version-update;junit:junit;external_dependency} -->
8181
<scope>test</scope>
8282
</dependency>
83+
<dependency>
84+
<groupId>org.testng</groupId>
85+
<artifactId>testng</artifactId>
86+
<version>6.14.3</version> <!-- {x-version-update;org.testng:testng;external_dependency} -->
87+
<scope>test</scope>
88+
</dependency>
89+
<dependency>
90+
<groupId>org.assertj</groupId>
91+
<artifactId>assertj-core</artifactId>
92+
<version>3.16.1</version> <!-- {x-version-update;org.assertj:assertj-core;external_dependency} -->
93+
<scope>test</scope>
94+
</dependency>
95+
8396
</dependencies>
8497

8598
<build>

sdk/cosmos/azure-cosmos-dotnet-benchmark/src/main/java/com/azure/cosmos/dotnet/benchmark/BenchmarkConfig.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ public class BenchmarkConfig {
1616
public final static String USER_AGENT_SUFFIX = "cosmosdbdotnetbenchmark";
1717

1818
@Parameter(names = "-w", description = "Type of Workload:\n"
19-
+ "\tReadTExists - run a READ workload that prints both throughput and latency *\n"
2019
+ "\tInsert - run a Insert workload that prints both throughput and latency\n"
20+
+ "\tInsertWithoutExplicitPKAndId - same as Insert, but parsing PK and id from ObjectNode\n"
2121
, converter = Operation.OperationTypeConverter.class)
2222
private Operation operation = Operation.Insert;
2323

@@ -239,8 +239,8 @@ public boolean isHelp() {
239239
}
240240

241241
public enum Operation {
242-
ReadTExists,
243-
Insert;
242+
Insert,
243+
InsertWithoutExplicitPKAndId;
244244

245245
static Operation fromString(String code) {
246246

sdk/cosmos/azure-cosmos-dotnet-benchmark/src/main/java/com/azure/cosmos/dotnet/benchmark/IBenchmarkOperation.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
14
package com.azure.cosmos.dotnet.benchmark;
25

36
import reactor.core.publisher.Mono;

sdk/cosmos/azure-cosmos-dotnet-benchmark/src/main/java/com/azure/cosmos/dotnet/benchmark/IExecutionStrategy.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
14
package com.azure.cosmos.dotnet.benchmark;
25

3-
import com.azure.cosmos.implementation.guava25.base.Function;
6+
import java.util.function.Supplier;
47

58
interface IExecutionStrategy {
69
RunSummary execute(
@@ -11,7 +14,7 @@ RunSummary execute(
1114

1215
static IExecutionStrategy startNew(
1316
BenchmarkConfig config,
14-
Function<Void, IBenchmarkOperation> benchmarkOperation) {
17+
Supplier<IBenchmarkOperation> benchmarkOperation) {
1518

1619
return new ParallelExecutionStrategy(config, benchmarkOperation);
1720
}

sdk/cosmos/azure-cosmos-dotnet-benchmark/src/main/java/com/azure/cosmos/dotnet/benchmark/IExecutor.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
14
package com.azure.cosmos.dotnet.benchmark;
25

36
import reactor.core.publisher.Mono;

sdk/cosmos/azure-cosmos-dotnet-benchmark/src/main/java/com/azure/cosmos/dotnet/benchmark/JsonHelper.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
14
package com.azure.cosmos.dotnet.benchmark;
25

36
import com.azure.cosmos.implementation.Utils;

sdk/cosmos/azure-cosmos-dotnet-benchmark/src/main/java/com/azure/cosmos/dotnet/benchmark/Main.java

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import com.azure.cosmos.CosmosClientBuilder;
99
import com.azure.cosmos.ThrottlingRetryOptions;
1010
import com.azure.cosmos.dotnet.benchmark.operations.InsertBenchmarkOperation;
11-
import com.azure.cosmos.implementation.guava25.base.Function;
1211
import com.azure.cosmos.models.CosmosItemResponse;
1312
import com.azure.cosmos.models.PartitionKey;
1413
import com.azure.cosmos.models.PartitionKeyDefinition;
@@ -25,6 +24,7 @@
2524
import java.time.ZoneOffset;
2625
import java.time.format.DateTimeFormatter;
2726
import java.util.Objects;
27+
import java.util.function.Supplier;
2828

2929
public class Main {
3030

@@ -99,7 +99,7 @@ public static void main(String[] args) throws Exception {
9999
Utility.traceInformation("");
100100

101101
int opsPerTask = cfg.getItemCount() / taskCount;
102-
Function<Void, IBenchmarkOperation> benchmarkFactory =
102+
Supplier<IBenchmarkOperation> benchmarkFactory =
103103
getBenchmarkFactory(cfg, partitionKeyPath, cosmosClient);
104104

105105
IExecutionStrategy execution = IExecutionStrategy.startNew(cfg, benchmarkFactory);
@@ -167,21 +167,35 @@ public static void main(String[] args) throws Exception {
167167
cosmosClient.close();
168168
}
169169
}
170-
171170
}
172171

173-
private static Function<Void, IBenchmarkOperation> getBenchmarkFactory(
172+
private static Supplier<IBenchmarkOperation> getBenchmarkFactory(
174173
BenchmarkConfig cfg,
175174
String partitionKeyPath,
176175
CosmosAsyncClient cosmosClient) throws IOException {
177176

178177
String sampleItem = new String(Files.readAllBytes(Paths.get(cfg.getItemTemplateFile())));
179178

180-
return (dummy) -> new InsertBenchmarkOperation(
181-
cosmosClient,
182-
cfg.getDatabase(),
183-
cfg.getContainer(),
184-
partitionKeyPath,
185-
sampleItem);
179+
switch (cfg.getOperation())
180+
{
181+
case InsertWithoutExplicitPKAndId:
182+
return () -> new InsertBenchmarkOperation(
183+
cosmosClient,
184+
cfg.getDatabase(),
185+
cfg.getContainer(),
186+
partitionKeyPath,
187+
sampleItem,
188+
false);
189+
default:
190+
return () -> new InsertBenchmarkOperation(
191+
cosmosClient,
192+
cfg.getDatabase(),
193+
cfg.getContainer(),
194+
partitionKeyPath,
195+
sampleItem,
196+
true);
197+
}
198+
199+
186200
}
187201
}

sdk/cosmos/azure-cosmos-dotnet-benchmark/src/main/java/com/azure/cosmos/dotnet/benchmark/OperationResult.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
14
package com.azure.cosmos.dotnet.benchmark;
25

36
import com.azure.cosmos.implementation.guava25.base.Function;

sdk/cosmos/azure-cosmos-dotnet-benchmark/src/main/java/com/azure/cosmos/dotnet/benchmark/ParallelExecutionStrategy.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
14
package com.azure.cosmos.dotnet.benchmark;
25

3-
import com.azure.cosmos.implementation.guava25.base.Function;
46
import reactor.core.publisher.Flux;
57
import reactor.core.scheduler.Schedulers;
68

@@ -17,12 +19,12 @@
1719

1820
public class ParallelExecutionStrategy implements IExecutionStrategy {
1921
private static final long OUTPUT_LOOP_DELAY_IN_MS = 1000;
20-
private final Function<Void, IBenchmarkOperation> benchmarkOperation;
22+
private final Supplier<IBenchmarkOperation> benchmarkOperation;
2123
private final BenchmarkConfig config;
2224
private final AtomicInteger pendingExecutorCount = new AtomicInteger();
2325

2426
public ParallelExecutionStrategy(BenchmarkConfig config,
25-
Function<Void, IBenchmarkOperation> benchmarkOperation) {
27+
Supplier<IBenchmarkOperation> benchmarkOperation) {
2628

2729
this.config = config;
2830
this.benchmarkOperation = benchmarkOperation;
@@ -37,7 +39,7 @@ public RunSummary execute(
3739

3840
IExecutor warmupExecutor = new SerialOperationExecutor(
3941
"Warmup",
40-
this.benchmarkOperation.apply(null));
42+
this.benchmarkOperation.get());
4143

4244
// Block while warmup happens
4345
warmupExecutor.execute(
@@ -62,7 +64,7 @@ public RunSummary execute(
6264
.flatMap((i) -> {
6365
executors[i] = new SerialOperationExecutor(
6466
String.valueOf(i),
65-
this.benchmarkOperation.apply(null));
67+
this.benchmarkOperation.get());
6668

6769
return executors[i].execute(
6870
serialExecutorIterationCount,

0 commit comments

Comments
 (0)