Skip to content

Commit eb81eb2

Browse files
jeet1995Copilot
andauthored
chore(benchmark): wire excludedRegionsList into Cosmos*RequestOptions (#49313)
Adds an excludedRegionsList field on TenantDefaultConfig (mirroring preferredRegionsList) and threads getExcludedRegionsList() into every Cosmos*RequestOptions constructed by the vanilla async/sync benchmark workloads (read, write, query, readMany, bulk). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 71d0c87 commit eb81eb2

10 files changed

Lines changed: 38 additions & 8 deletions

sdk/cosmos/azure-cosmos-benchmark/src/main/java/com/azure/cosmos/benchmark/AsyncBenchmark.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ abstract class AsyncBenchmark<T> implements Benchmark {
210210
});
211211

212212
CosmosBulkExecutionOptions bulkExecutionOptions = new CosmosBulkExecutionOptions();
213+
bulkExecutionOptions.setExcludedRegions(cfg.getExcludedRegionsList());
213214
List<CosmosBulkOperationResponse<Object>> failedResponses = Collections.synchronizedList(new ArrayList<>());
214215
cosmosAsyncContainer
215216
.executeBulkOperations(bulkOperationFlux, bulkExecutionOptions)

sdk/cosmos/azure-cosmos-benchmark/src/main/java/com/azure/cosmos/benchmark/AsyncQueryBenchmark.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ protected Mono<FeedResponse<PojoizedJson>> performWorkload(long i) {
4040
Flux<FeedResponse<PojoizedJson>> obs;
4141
Random r = new Random();
4242
CosmosQueryRequestOptions options = new CosmosQueryRequestOptions();
43+
options.setExcludedRegions(workloadConfig.getExcludedRegionsList());
4344

4445
if (workloadConfig.getOperationType() == Operation.QueryCross) {
4546

sdk/cosmos/azure-cosmos-benchmark/src/main/java/com/azure/cosmos/benchmark/AsyncQuerySinglePartitionMultiple.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class AsyncQuerySinglePartitionMultiple extends AsyncBenchmark<FeedResponse<Pojo
1919
super(cfg);
2020
options = new CosmosQueryRequestOptions();
2121
options.setPartitionKey(new PartitionKey("pk"));
22+
options.setExcludedRegions(cfg.getExcludedRegionsList());
2223
}
2324

2425
@Override

sdk/cosmos/azure-cosmos-benchmark/src/main/java/com/azure/cosmos/benchmark/AsyncReadBenchmark.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
package com.azure.cosmos.benchmark;
55

6+
import com.azure.cosmos.models.CosmosItemRequestOptions;
67
import com.azure.cosmos.models.CosmosItemResponse;
78
import com.azure.cosmos.models.PartitionKey;
89

@@ -18,8 +19,10 @@ class AsyncReadBenchmark extends AsyncBenchmark<PojoizedJson> {
1819
protected Mono<PojoizedJson> performWorkload(long i) {
1920
int index = (int) (i % docsToRead.size());
2021
PojoizedJson doc = docsToRead.get(index);
22+
CosmosItemRequestOptions options = new CosmosItemRequestOptions();
23+
options.setExcludedRegions(workloadConfig.getExcludedRegionsList());
2124
return cosmosAsyncContainer.readItem(doc.getId(),
22-
new PartitionKey(doc.getId()), PojoizedJson.class)
25+
new PartitionKey(doc.getId()), options, PojoizedJson.class)
2326
.map(CosmosItemResponse::getItem);
2427
}
2528
}

sdk/cosmos/azure-cosmos-benchmark/src/main/java/com/azure/cosmos/benchmark/AsyncReadManyBenchmark.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package com.azure.cosmos.benchmark;
55

66
import com.azure.cosmos.models.CosmosItemIdentity;
7+
import com.azure.cosmos.models.CosmosReadManyRequestOptions;
78
import com.azure.cosmos.models.FeedResponse;
89
import com.azure.cosmos.models.PartitionKey;
910

@@ -37,6 +38,8 @@ protected Mono<FeedResponse<PojoizedJson>> performWorkload(long i) {
3738
cosmosItemIdentities.add(new CosmosItemIdentity(partitionKey, doc.getId()));
3839
}
3940

40-
return cosmosAsyncContainer.readMany(cosmosItemIdentities, PojoizedJson.class);
41+
CosmosReadManyRequestOptions options = new CosmosReadManyRequestOptions();
42+
options.setExcludedRegions(workloadConfig.getExcludedRegionsList());
43+
return cosmosAsyncContainer.readMany(cosmosItemIdentities, options, PojoizedJson.class);
4144
}
4245
}

sdk/cosmos/azure-cosmos-benchmark/src/main/java/com/azure/cosmos/benchmark/AsyncWriteBenchmark.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
package com.azure.cosmos.benchmark;
55

6+
import com.azure.cosmos.models.CosmosItemRequestOptions;
67
import com.azure.cosmos.models.CosmosItemResponse;
78
import com.azure.cosmos.models.PartitionKey;
89

@@ -28,18 +29,21 @@ class AsyncWriteBenchmark extends AsyncBenchmark<CosmosItemResponse> {
2829
protected Mono<CosmosItemResponse> performWorkload(long i) {
2930
String id = uuid + i;
3031
Mono<? extends CosmosItemResponse<?>> result;
32+
CosmosItemRequestOptions options = new CosmosItemRequestOptions();
33+
options.setExcludedRegions(workloadConfig.getExcludedRegionsList());
3134
if (workloadConfig.isDisablePassingPartitionKeyAsOptionOnWrite()) {
3235
result = cosmosAsyncContainer.createItem(BenchmarkHelper.generateDocument(id,
3336
dataFieldValue,
3437
partitionKey,
35-
workloadConfig.getDocumentDataFieldCount()));
38+
workloadConfig.getDocumentDataFieldCount()),
39+
options);
3640
} else {
3741
result = cosmosAsyncContainer.createItem(BenchmarkHelper.generateDocument(id,
3842
dataFieldValue,
3943
partitionKey,
4044
workloadConfig.getDocumentDataFieldCount()),
4145
new PartitionKey(id),
42-
null);
46+
options);
4347
}
4448
// Raw type cast is required because CosmosItemResponse uses wildcard generics
4549
// that cannot be expressed in the class type parameter without propagating

sdk/cosmos/azure-cosmos-benchmark/src/main/java/com/azure/cosmos/benchmark/SyncBenchmark.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ private static ImplementationBridgeHelpers.CosmosClientHelper.CosmosClientAccess
186186
});
187187

188188
CosmosBulkExecutionOptions bulkExecutionOptions = new CosmosBulkExecutionOptions();
189+
bulkExecutionOptions.setExcludedRegions(workloadCfg.getExcludedRegionsList());
189190
List<CosmosBulkOperationResponse<Object>> failedResponses = Collections.synchronizedList(new ArrayList<>());
190191
asyncContainer
191192
.executeBulkOperations(bulkOperationFlux, bulkExecutionOptions)

sdk/cosmos/azure-cosmos-benchmark/src/main/java/com/azure/cosmos/benchmark/SyncReadBenchmark.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ protected CosmosItemResponse performWorkload(long i) throws Exception {
2121
PojoizedJson doc = docsToRead.get(index);
2222

2323
String partitionKeyValue = doc.getId();
24+
CosmosItemRequestOptions options = new CosmosItemRequestOptions();
25+
options.setExcludedRegions(workloadConfig.getExcludedRegionsList());
2426
return cosmosContainer.readItem(doc.getId(), new PartitionKey(partitionKeyValue),
25-
new CosmosItemRequestOptions(), InternalObjectNode.class);
27+
options, InternalObjectNode.class);
2628
}
2729
}

sdk/cosmos/azure-cosmos-benchmark/src/main/java/com/azure/cosmos/benchmark/SyncWriteBenchmark.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
package com.azure.cosmos.benchmark;
55

6+
import com.azure.cosmos.models.CosmosItemRequestOptions;
67
import com.azure.cosmos.models.CosmosItemResponse;
78
import com.azure.cosmos.models.PartitionKey;
89
import org.apache.commons.lang3.RandomStringUtils;
@@ -26,13 +27,15 @@ class SyncWriteBenchmark extends SyncBenchmark<CosmosItemResponse> {
2627
@Override
2728
protected CosmosItemResponse performWorkload(long i) throws Exception {
2829
String id = uuid + i;
29-
CosmosItemResponse<PojoizedJson> response;
30+
CosmosItemRequestOptions options = new CosmosItemRequestOptions();
31+
options.setExcludedRegions(workloadConfig.getExcludedRegionsList());
3032
if (workloadConfig.isDisablePassingPartitionKeyAsOptionOnWrite()) {
3133
// require parsing partition key from the doc
3234
return cosmosContainer.createItem(BenchmarkHelper.generateDocument(id,
3335
dataFieldValue,
3436
partitionKey,
35-
workloadConfig.getDocumentDataFieldCount()));
37+
workloadConfig.getDocumentDataFieldCount()),
38+
options);
3639
}
3740

3841
// more optimized for write as partition key is already passed as config
@@ -41,6 +44,6 @@ protected CosmosItemResponse performWorkload(long i) throws Exception {
4144
partitionKey,
4245
workloadConfig.getDocumentDataFieldCount()),
4346
new PartitionKey(id),
44-
null);
47+
options);
4548
}
4649
}

sdk/cosmos/azure-cosmos-benchmark/src/main/java/com/azure/cosmos/benchmark/TenantDefaultConfig.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ class TenantDefaultConfig {
140140
@JsonProperty("preferredRegionsList")
141141
protected String preferredRegionsList;
142142

143+
@JsonProperty("excludedRegionsList")
144+
protected String excludedRegionsList;
145+
143146
@JsonProperty("manageDatabase")
144147
protected Boolean manageDatabase;
145148

@@ -233,6 +236,13 @@ public List<String> getPreferredRegionsList() {
233236
return regions;
234237
}
235238

239+
public List<String> getExcludedRegionsList() {
240+
if (excludedRegionsList == null || excludedRegionsList.isEmpty()) return null;
241+
List<String> regions = new ArrayList<>();
242+
for (String r : excludedRegionsList.split(",")) { regions.add(r.trim()); }
243+
return regions;
244+
}
245+
236246
public boolean shouldManageDatabase() { return manageDatabase != null ? manageDatabase : false; }
237247
public String getApplicationName() { return applicationName != null ? applicationName : ""; }
238248
public boolean isManagedIdentityRequired() { return isManagedIdentityRequired != null && isManagedIdentityRequired; }
@@ -278,6 +288,7 @@ void applyTo(TenantWorkloadConfig tenant) {
278288
if (http2Enabled != null && tenant.http2Enabled == null) tenant.http2Enabled = http2Enabled;
279289
if (http2MaxConcurrentStreams != null && tenant.http2MaxConcurrentStreams == null) tenant.http2MaxConcurrentStreams = http2MaxConcurrentStreams;
280290
if (preferredRegionsList != null && tenant.preferredRegionsList == null) tenant.preferredRegionsList = preferredRegionsList;
291+
if (excludedRegionsList != null && tenant.excludedRegionsList == null) tenant.excludedRegionsList = excludedRegionsList;
281292
if (manageDatabase != null && tenant.manageDatabase == null) tenant.manageDatabase = manageDatabase;
282293
if (isManagedIdentityRequired != null && tenant.isManagedIdentityRequired == null) tenant.isManagedIdentityRequired = isManagedIdentityRequired;
283294
if (applicationName != null && tenant.applicationName == null) tenant.applicationName = applicationName;

0 commit comments

Comments
 (0)