Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion sdk/cosmos/azure-cosmos-dotnet-benchmark/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ Copyright (C) 2019 CosmosBenchmark

--partitionKeyPath Container partition key path

-pl Degree of parallism
-pl Degree of parallism

-w Workload name

--itemTemplateFile Item template

Expand Down
13 changes: 13 additions & 0 deletions sdk/cosmos/azure-cosmos-dotnet-benchmark/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,19 @@ Licensed under the MIT License.
<version>4.13.1</version> <!-- {x-version-update;junit:junit;external_dependency} -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.3</version> <!-- {x-version-update;org.testng:testng;external_dependency} -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.16.1</version> <!-- {x-version-update;org.assertj:assertj-core;external_dependency} -->
<scope>test</scope>
</dependency>

</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public class BenchmarkConfig {
public final static String USER_AGENT_SUFFIX = "cosmosdbdotnetbenchmark";

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

Expand Down Expand Up @@ -239,8 +239,8 @@ public boolean isHelp() {
}

public enum Operation {
ReadTExists,
Insert;
Insert,
InsertWithoutExplicitPKAndId;

static Operation fromString(String code) {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.cosmos.dotnet.benchmark;

import reactor.core.publisher.Mono;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.cosmos.dotnet.benchmark;

import com.azure.cosmos.implementation.guava25.base.Function;
import java.util.function.Supplier;

interface IExecutionStrategy {
RunSummary execute(
Expand All @@ -11,7 +14,7 @@ RunSummary execute(

static IExecutionStrategy startNew(
BenchmarkConfig config,
Function<Void, IBenchmarkOperation> benchmarkOperation) {
Supplier<IBenchmarkOperation> benchmarkOperation) {

return new ParallelExecutionStrategy(config, benchmarkOperation);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.cosmos.dotnet.benchmark;

import reactor.core.publisher.Mono;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.cosmos.dotnet.benchmark;

import com.azure.cosmos.implementation.Utils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.azure.cosmos.CosmosClientBuilder;
import com.azure.cosmos.ThrottlingRetryOptions;
import com.azure.cosmos.dotnet.benchmark.operations.InsertBenchmarkOperation;
import com.azure.cosmos.implementation.guava25.base.Function;
import com.azure.cosmos.models.CosmosItemResponse;
import com.azure.cosmos.models.PartitionKey;
import com.azure.cosmos.models.PartitionKeyDefinition;
Expand All @@ -25,6 +24,7 @@
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.Objects;
import java.util.function.Supplier;

public class Main {

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

int opsPerTask = cfg.getItemCount() / taskCount;
Function<Void, IBenchmarkOperation> benchmarkFactory =
Supplier<IBenchmarkOperation> benchmarkFactory =
getBenchmarkFactory(cfg, partitionKeyPath, cosmosClient);

IExecutionStrategy execution = IExecutionStrategy.startNew(cfg, benchmarkFactory);
Expand Down Expand Up @@ -167,21 +167,35 @@ public static void main(String[] args) throws Exception {
cosmosClient.close();
}
}

}

private static Function<Void, IBenchmarkOperation> getBenchmarkFactory(
private static Supplier<IBenchmarkOperation> getBenchmarkFactory(
BenchmarkConfig cfg,
String partitionKeyPath,
CosmosAsyncClient cosmosClient) throws IOException {

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

return (dummy) -> new InsertBenchmarkOperation(
cosmosClient,
cfg.getDatabase(),
cfg.getContainer(),
partitionKeyPath,
sampleItem);
switch (cfg.getOperation())
{
case InsertWithoutExplicitPKAndId:
return () -> new InsertBenchmarkOperation(
cosmosClient,
cfg.getDatabase(),
cfg.getContainer(),
partitionKeyPath,
sampleItem,
false);
default:
return () -> new InsertBenchmarkOperation(
cosmosClient,
cfg.getDatabase(),
cfg.getContainer(),
partitionKeyPath,
sampleItem,
true);
}


}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.cosmos.dotnet.benchmark;

import com.azure.cosmos.implementation.guava25.base.Function;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.cosmos.dotnet.benchmark;

import com.azure.cosmos.implementation.guava25.base.Function;
import reactor.core.publisher.Flux;
import reactor.core.scheduler.Schedulers;

Expand All @@ -17,12 +19,12 @@

public class ParallelExecutionStrategy implements IExecutionStrategy {
private static final long OUTPUT_LOOP_DELAY_IN_MS = 1000;
private final Function<Void, IBenchmarkOperation> benchmarkOperation;
private final Supplier<IBenchmarkOperation> benchmarkOperation;
private final BenchmarkConfig config;
private final AtomicInteger pendingExecutorCount = new AtomicInteger();

public ParallelExecutionStrategy(BenchmarkConfig config,
Function<Void, IBenchmarkOperation> benchmarkOperation) {
Supplier<IBenchmarkOperation> benchmarkOperation) {

this.config = config;
this.benchmarkOperation = benchmarkOperation;
Expand All @@ -37,7 +39,7 @@ public RunSummary execute(

IExecutor warmupExecutor = new SerialOperationExecutor(
"Warmup",
this.benchmarkOperation.apply(null));
this.benchmarkOperation.get());

// Block while warmup happens
warmupExecutor.execute(
Expand All @@ -62,7 +64,7 @@ public RunSummary execute(
.flatMap((i) -> {
executors[i] = new SerialOperationExecutor(
String.valueOf(i),
this.benchmarkOperation.apply(null));
this.benchmarkOperation.get());

return executors[i].execute(
serialExecutorIterationCount,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.cosmos.dotnet.benchmark;

import com.fasterxml.jackson.annotation.JsonProperty;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.cosmos.dotnet.benchmark;

import reactor.core.publisher.Flux;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.cosmos.dotnet.benchmark;

class Summary {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.cosmos.dotnet.benchmark;

import java.util.Arrays;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.cosmos.dotnet.benchmark.operations;

import com.azure.cosmos.CosmosAsyncClient;
Expand All @@ -18,20 +21,23 @@ public class InsertBenchmarkOperation implements IBenchmarkOperation {
private final String databaseName;
private final String partitionKeyPath;
private final ObjectNode sampleJsonNode;
private final boolean explicitlyProvidePKAndId;
private PartitionKey partitionKey;

public InsertBenchmarkOperation(
CosmosAsyncClient cosmosClient,
String databaseName,
String containerName,
String partitionKeyPath,
String sampleJson) {
String sampleJson,
boolean explicitlyProvidePKAndId) {

this.databaseName = databaseName;
this.containerName = containerName;
this.partitionKeyPath = partitionKeyPath.replace("/", "");
this.sampleJsonNode = (ObjectNode)JsonHelper.fromJsonString(sampleJson);
this.container = cosmosClient.getDatabase(databaseName).getContainer(containerName);
this.explicitlyProvidePKAndId = explicitlyProvidePKAndId;
}

@Override
Expand All @@ -52,10 +58,12 @@ public Mono<Object> prepare() {

@Override
public Mono<OperationResult> executeOnce() {
Mono<CosmosItemResponse<ObjectNode>> createTask = this.container.createItem(
this.sampleJsonNode,
this.partitionKey,
null);
Mono<CosmosItemResponse<ObjectNode>> createTask = this.explicitlyProvidePKAndId ?
this.container.createItem(
this.sampleJsonNode,
this.partitionKey,
null)
: this.container.createItem(this.sampleJsonNode);

return createTask
.map((r) -> {
Expand Down
Loading