diff --git a/sdk/cosmos/azure-cosmos-benchmark/ctl/run_benchmark.sh b/sdk/cosmos/azure-cosmos-benchmark/ctl/run_benchmark.sh index 80c8c3ccb96c..0b0ace17f00d 100644 --- a/sdk/cosmos/azure-cosmos-benchmark/ctl/run_benchmark.sh +++ b/sdk/cosmos/azure-cosmos-benchmark/ctl/run_benchmark.sh @@ -95,9 +95,9 @@ additional_benchmark_options="-documentDataFieldSize 10 -documentDataFieldCount additional_benchmark_options="$additional_benchmark_options -maxConnectionPoolSize $gateway_connection_poolsize" if [ -z "$ctl_graphite_endpoint" ]; then - java -Xmx8g -Xms8g $jvm_opt -Dcosmos.directModeProtocol=$protocol -Dazure.cosmos.directModeProtocol=$protocol -DCOSMOS.ENVIRONMENT_NAME=$ctl_env -DCOSMOS.CLIENT_TELEMETRY_ENDPOINT=$ctl_client_telemetry_endpoint -jar "$jar_file" -serviceEndpoint "$service_endpoint" -masterKey "$master_key" -databaseId "$db_name" -collectionId "$col_name" -readWriteQueryPct "$read_write_query_pct" -diagnosticsThresholdDuration "$diagnostics_threshold_duration" -numberOfCollectionForCtl "$number_Of_collection" -throughput $throughput -consistencyLevel $consistency_level -concurrency $concurrency -numberOfOperations $number_of_operations -operation $operation -connectionMode $connection_mode -maxRunningTimeDuration $max_running_time_duration -numberOfPreCreatedDocuments $number_of_precreated_documents $additional_benchmark_options 2>&1 | tee -a "$log_filename" + java -Xmx8g -Xms8g $jvm_opt -Dcosmos.directModeProtocol=$protocol -Dazure.cosmos.directModeProtocol=$protocol -DCOSMOS.ENVIRONMENT_NAME=$ctl_env -DCOSMOS.CLIENT_TELEMETRY_ENDPOINT=$ctl_client_telemetry_endpoint -jar "$jar_file" -serviceEndpoint "$service_endpoint" -masterKey "$master_key" -databaseId "$db_name" -collectionId "$col_name" -readWriteQueryPct "$read_write_query_pct" -diagnosticsThresholdDuration "$diagnostics_threshold_duration" -numberOfCollectionForCtl "$number_Of_collection" -throughput $throughput -consistencyLevel $consistency_level -concurrency $concurrency -numberOfOperations $number_of_operations -operation $operation -connectionMode $connection_mode -maxRunningTimeDuration $max_running_time_duration -numberOfPreCreatedDocuments $number_of_precreated_documents -preferredRegionsList $ctl_preferred_regions $additional_benchmark_options 2>&1 | tee -a "$log_filename" else - java -Xmx8g -Xms8g $jvm_opt -Dcosmos.directModeProtocol=$protocol -Dazure.cosmos.directModeProtocol=$protocol -DCOSMOS.ENVIRONMENT_NAME=$ctl_env -DCOSMOS.CLIENT_TELEMETRY_ENDPOINT=$ctl_client_telemetry_endpoint -jar "$jar_file" -serviceEndpoint "$service_endpoint" -masterKey "$master_key" -databaseId "$db_name" -collectionId "$col_name" -readWriteQueryPct "$read_write_query_pct" -diagnosticsThresholdDuration "$diagnostics_threshold_duration" -numberOfCollectionForCtl "$number_Of_collection" -throughput $throughput -consistencyLevel $consistency_level -concurrency $concurrency -numberOfOperations $number_of_operations -operation $operation -connectionMode $connection_mode -maxRunningTimeDuration $max_running_time_duration -graphiteEndpoint $ctl_graphite_endpoint -numberOfPreCreatedDocuments $number_of_precreated_documents $ctl_accountNameInGraphiteReporter $additional_benchmark_options 2>&1 | tee -a "$log_filename" + java -Xmx8g -Xms8g $jvm_opt -Dcosmos.directModeProtocol=$protocol -Dazure.cosmos.directModeProtocol=$protocol -DCOSMOS.ENVIRONMENT_NAME=$ctl_env -DCOSMOS.CLIENT_TELEMETRY_ENDPOINT=$ctl_client_telemetry_endpoint -jar "$jar_file" -serviceEndpoint "$service_endpoint" -masterKey "$master_key" -databaseId "$db_name" -collectionId "$col_name" -readWriteQueryPct "$read_write_query_pct" -diagnosticsThresholdDuration "$diagnostics_threshold_duration" -numberOfCollectionForCtl "$number_Of_collection" -throughput $throughput -consistencyLevel $consistency_level -concurrency $concurrency -numberOfOperations $number_of_operations -operation $operation -connectionMode $connection_mode -maxRunningTimeDuration $max_running_time_duration -graphiteEndpoint $ctl_graphite_endpoint -numberOfPreCreatedDocuments $number_of_precreated_documents -preferredRegionsList $ctl_preferred_regions $ctl_accountNameInGraphiteReporter $additional_benchmark_options 2>&1 | tee -a "$log_filename" fi end=$(date +%s) diff --git a/sdk/cosmos/azure-cosmos-benchmark/src/main/java/com/azure/cosmos/benchmark/AsynReadWithMultipleClients.java b/sdk/cosmos/azure-cosmos-benchmark/src/main/java/com/azure/cosmos/benchmark/AsynReadWithMultipleClients.java index f7e620f4c579..87774c5f07a6 100644 --- a/sdk/cosmos/azure-cosmos-benchmark/src/main/java/com/azure/cosmos/benchmark/AsynReadWithMultipleClients.java +++ b/sdk/cosmos/azure-cosmos-benchmark/src/main/java/com/azure/cosmos/benchmark/AsynReadWithMultipleClients.java @@ -194,6 +194,7 @@ private void createClients() { CosmosClientBuilder cosmosClientBuilder = new CosmosClientBuilder() .endpoint(endpoint) .key(key) + .preferredRegions(this.configuration.getPreferredRegionsList()) .consistencyLevel(configuration.getConsistencyLevel()) .connectionSharingAcrossClientsEnabled(true) .contentResponseOnWriteEnabled(Boolean.parseBoolean(configuration.isContentResponseOnWriteEnabled())); diff --git a/sdk/cosmos/azure-cosmos-benchmark/src/main/java/com/azure/cosmos/benchmark/AsyncBenchmark.java b/sdk/cosmos/azure-cosmos-benchmark/src/main/java/com/azure/cosmos/benchmark/AsyncBenchmark.java index 66f64cd8f098..f990df59613d 100644 --- a/sdk/cosmos/azure-cosmos-benchmark/src/main/java/com/azure/cosmos/benchmark/AsyncBenchmark.java +++ b/sdk/cosmos/azure-cosmos-benchmark/src/main/java/com/azure/cosmos/benchmark/AsyncBenchmark.java @@ -79,6 +79,7 @@ abstract class AsyncBenchmark { CosmosClientBuilder cosmosClientBuilder = new CosmosClientBuilder() .endpoint(cfg.getServiceEndpoint()) .key(cfg.getMasterKey()) + .preferredRegions(cfg.getPreferredRegionsList()) .consistencyLevel(cfg.getConsistencyLevel()) .contentResponseOnWriteEnabled(Boolean.parseBoolean(cfg.isContentResponseOnWriteEnabled())); if (cfg.getConnectionMode().equals(ConnectionMode.DIRECT)) { diff --git a/sdk/cosmos/azure-cosmos-benchmark/src/main/java/com/azure/cosmos/benchmark/Configuration.java b/sdk/cosmos/azure-cosmos-benchmark/src/main/java/com/azure/cosmos/benchmark/Configuration.java index 6f4f006a9442..815d6b2db73a 100644 --- a/sdk/cosmos/azure-cosmos-benchmark/src/main/java/com/azure/cosmos/benchmark/Configuration.java +++ b/sdk/cosmos/azure-cosmos-benchmark/src/main/java/com/azure/cosmos/benchmark/Configuration.java @@ -27,7 +27,9 @@ import java.net.InetAddress; import java.net.UnknownHostException; import java.time.Duration; +import java.util.ArrayList; import java.util.Arrays; +import java.util.List; public class Configuration { @@ -91,6 +93,10 @@ public class Configuration { @Parameter(names = "-manageDatabase", description = "Control switch for creating/deleting underlying database resource") private boolean manageDatabase = false; + @Parameter(names = "-preferredRegionsList", listConverter = PreferredRegionsConverter.class, description = "Comma" + + " separated preferred regions list") + private List preferredRegionsList; + @Parameter(names = "-operation", description = "Type of Workload:\n" + "\tReadThroughput- run a READ workload that prints only throughput *\n" + "\tReadThroughputWithMultipleClients - run a READ workload that prints throughput and latency for multiple client read.*\n" @@ -445,6 +451,10 @@ public String toString() { return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE); } + public List getPreferredRegionsList() { + return preferredRegionsList; + } + public void tryGetValuesFromSystem() { serviceEndpoint = StringUtils.defaultString(Strings.emptyToNull(System.getenv().get("SERVICE_END_POINT")), serviceEndpoint); @@ -483,6 +493,11 @@ public void tryGetValuesFromSystem() { String throughputValue = StringUtils.defaultString( Strings.emptyToNull(System.getenv().get("THROUGHPUT")), Integer.toString(throughput)); throughput = Integer.parseInt(throughputValue); + + if (StringUtils.isNotEmpty(System.getenv().get("PREFERRED_REGIONS_LIST"))) { + PreferredRegionsConverter preferredRegionsConverter = new PreferredRegionsConverter(); + preferredRegionsList = preferredRegionsConverter.convert(System.getenv().get("PREFERRED_REGIONS_LIST")); + } } private synchronized MeterRegistry azureMonitorMeterRegistry(String instrumentationKey) { @@ -592,4 +607,18 @@ public String[] tagsAsPrefix() { return this.graphiteMeterRegistry; } + + private class PreferredRegionsConverter implements IStringConverter> { + @Override + public List convert(String preferredRegionsList) { + List preferredRegions = null; + if (StringUtils.isNotEmpty(preferredRegionsList)) { + String[] preferredArray = preferredRegionsList.split(","); + if (preferredArray != null && preferredArray.length > 0) { + preferredRegions = new ArrayList<>(Arrays.asList(preferredArray)); + } + } + return preferredRegions; + } + } } diff --git a/sdk/cosmos/azure-cosmos-benchmark/src/main/java/com/azure/cosmos/benchmark/SyncBenchmark.java b/sdk/cosmos/azure-cosmos-benchmark/src/main/java/com/azure/cosmos/benchmark/SyncBenchmark.java index 93290e14c2cc..65e10d4fb42f 100644 --- a/sdk/cosmos/azure-cosmos-benchmark/src/main/java/com/azure/cosmos/benchmark/SyncBenchmark.java +++ b/sdk/cosmos/azure-cosmos-benchmark/src/main/java/com/azure/cosmos/benchmark/SyncBenchmark.java @@ -106,6 +106,7 @@ public T apply(T o, Throwable throwable) { CosmosClientBuilder cosmosClientBuilder = new CosmosClientBuilder() .endpoint(cfg.getServiceEndpoint()) + .preferredRegions(cfg.getPreferredRegionsList()) .key(cfg.getMasterKey()) .consistencyLevel(cfg.getConsistencyLevel()) .contentResponseOnWriteEnabled(Boolean.parseBoolean(cfg.isContentResponseOnWriteEnabled())); diff --git a/sdk/cosmos/azure-cosmos-benchmark/src/main/java/com/azure/cosmos/benchmark/ctl/AsyncCtlWorkload.java b/sdk/cosmos/azure-cosmos-benchmark/src/main/java/com/azure/cosmos/benchmark/ctl/AsyncCtlWorkload.java index 1f85e237fead..1a71818de518 100644 --- a/sdk/cosmos/azure-cosmos-benchmark/src/main/java/com/azure/cosmos/benchmark/ctl/AsyncCtlWorkload.java +++ b/sdk/cosmos/azure-cosmos-benchmark/src/main/java/com/azure/cosmos/benchmark/ctl/AsyncCtlWorkload.java @@ -31,7 +31,18 @@ import com.codahale.metrics.jvm.GarbageCollectorMetricSet; import com.codahale.metrics.jvm.MemoryUsageGaugeSet; import io.micrometer.core.instrument.MeterRegistry; +import org.apache.commons.lang3.RandomStringUtils; +import org.apache.commons.lang3.StringUtils; +import org.mpierce.metrics.reservoir.hdrhistogram.HdrHistogramResetOnSnapshotReservoir; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import reactor.core.publisher.BaseSubscriber; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; +import reactor.core.scheduler.Schedulers; + import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -40,14 +51,6 @@ import java.util.concurrent.Semaphore; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicLong; -import org.apache.commons.lang3.RandomStringUtils; -import org.mpierce.metrics.reservoir.hdrhistogram.HdrHistogramResetOnSnapshotReservoir; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import reactor.core.publisher.BaseSubscriber; -import reactor.core.publisher.Flux; -import reactor.core.publisher.Mono; -import reactor.core.scheduler.Schedulers; public class AsyncCtlWorkload { @@ -87,6 +90,7 @@ public AsyncCtlWorkload(Configuration cfg) { CosmosClientBuilder cosmosClientBuilder = new CosmosClientBuilder() .endpoint(cfg.getServiceEndpoint()) .key(cfg.getMasterKey()) + .preferredRegions(cfg.getPreferredRegionsList()) .consistencyLevel(cfg.getConsistencyLevel()) .clientTelemetryEnabled(true) .contentResponseOnWriteEnabled(Boolean.parseBoolean(cfg.isContentResponseOnWriteEnabled()));