Skip to content

Commit 89a6b4b

Browse files
Merge pull request #284027 from TheovanKraay/patch-80
Update performance-tips-java-sdk-v4.md
2 parents 0285db4 + d987d75 commit 89a6b4b

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

articles/cosmos-db/nosql/performance-tips-java-sdk-v4.md

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,30 @@ These techniques provide advanced mechanisms to address specific latency and ava
6363

6464
### Threshold-based availability strategy
6565

66-
The threshold-based availability strategy can improve tail latency and availability by sending parallel read requests to secondary regions and accepting the fastest response. This approach can drastically reduce the impact of regional outages or high-latency conditions on application performance.
66+
The threshold-based availability strategy can improve tail latency and availability by sending parallel read requests to secondary regions and accepting the fastest response. This approach can drastically reduce the impact of regional outages or high-latency conditions on application performance. Additionally, proactive connection management can be employed to further enhance performance by warming up connections and caches across both the current read region and preferred remote regions.
6767

6868
**Example configuration:**
6969
```java
70+
// Proactive Connection Management
71+
CosmosContainerIdentity containerIdentity = new CosmosContainerIdentity("sample_db_id", "sample_container_id");
72+
int proactiveConnectionRegionsCount = 2;
73+
Duration aggressiveWarmupDuration = Duration.ofSeconds(1);
74+
75+
CosmosAsyncClient clientWithOpenConnections = new CosmosClientBuilder()
76+
.endpoint("<account URL goes here")
77+
.key("<account key goes here>")
78+
.endpointDiscoveryEnabled(true)
79+
.preferredRegions(Arrays.asList("sample_region_1", "sample_region_2"))
80+
.openConnectionsAndInitCaches(new CosmosContainerProactiveInitConfigBuilder(Arrays.asList(containerIdentity))
81+
.setProactiveConnectionRegionsCount(proactiveConnectionRegionsCount)
82+
//setting aggressive warmup duration helps in cases where there is a high no. of partitions
83+
.setAggressiveWarmupDuration(aggressiveWarmupDuration)
84+
.build())
85+
.directMode()
86+
.buildAsyncClient();
87+
88+
CosmosAsyncContainer container = clientWithOpenConnections.getDatabase("sample_db_id").getContainer("sample_container_id");
89+
7090
int threshold = 500;
7191
int thresholdStep = 100;
7292

@@ -79,8 +99,8 @@ options.setCosmosEndToEndOperationLatencyPolicyConfig(config);
7999

80100
container.readItem("id", new PartitionKey("pk"), options, JsonNode.class).block();
81101

82-
//Write operations can benefit from threshold-based availability strategy if opted into non-idempotent write retry policy
83-
//and the account is configured for multi-region writes.
102+
// Write operations can benefit from threshold-based availability strategy if opted into non-idempotent write retry policy
103+
// and the account is configured for multi-region writes.
84104
options.setNonIdempotentWriteRetryPolicy(true, true);
85105
container.createItem("id", new PartitionKey("pk"), options, JsonNode.class).block();
86106
```
@@ -95,6 +115,8 @@ container.createItem("id", new PartitionKey("pk"), options, JsonNode.class).bloc
95115

96116
4. **Fastest Response Wins:** Whichever region responds first, that response is accepted, and the other parallel requests are ignored.
97117

118+
Proactive connection management helps by warming up connections and caches for containers across the preferred regions, reducing cold-start latency for failover scenarios or writes in multi-region setups.
119+
98120
This strategy can significantly improve latency in scenarios where a particular region is slow or temporarily unavailable, but it may incur more cost in terms of request units when parallel cross-region requests are required.
99121

100122
> [!NOTE]

0 commit comments

Comments
 (0)