Skip to content

Commit 7ed4446

Browse files
authored
Cosmos DB Performance fixes (#691)
1 parent 81721d3 commit 7ed4446

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

gxcosmosdb/src/main/java/com/genexus/db/cosmosdb/CosmosDBConnection.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,9 @@ private void initializeDBConnection(String connUrl) throws Exception
7474
.endpoint(maccountEndpoint)
7575
.key(maccountKey)
7676
.consistencyLevel(ConsistencyLevel.EVENTUAL)
77-
.contentResponseOnWriteEnabled(true)
77+
//.contentResponseOnWriteEnabled(true) Disabled for performance
7878
.preferredRegions(Collections.singletonList(mregion))
79+
.connectionSharingAcrossClientsEnabled(true)
7980
.buildAsyncClient();
8081

8182
cosmosDatabase = cosmosClient.getDatabase(mdatabase);

gxcosmosdb/src/main/java/com/genexus/db/cosmosdb/CosmosDBPreparedStatement.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import com.genexus.util.NameValuePair;
1818
import json.org.json.JSONException;
1919
import json.org.json.JSONObject;
20+
import reactor.core.Disposable;
2021
import reactor.core.publisher.Mono;
2122

2223
import java.io.InputStream;
@@ -45,7 +46,7 @@ public class CosmosDBPreparedStatement extends ServicePreparedStatement
4546
super(con, parms, gxCon);
4647
this.query = query;
4748
this.cursor = cursor;
48-
getCointainer(query.tableName);
49+
getContainer(query.tableName);
4950
}
5051
@Override
5152
public ResultSet executeQuery() throws SQLException
@@ -135,7 +136,7 @@ private int _executeQuery(CosmosDBResultSet resultSet) throws Exception {
135136
CosmosAsyncDatabase getDatabase() throws SQLException {
136137
return ((CosmosDBConnection)getConnection()).cosmosDatabase;
137138
}
138-
private void getCointainer(String containerName) throws SQLException {
139+
private void getContainer(String containerName) throws SQLException {
139140
container = getDatabase().getContainer(containerName);
140141
}
141142

@@ -223,8 +224,9 @@ private int[] deleteDocument(String idValue, Object partitionKey) throws Excepti
223224
statusCode[0] = 404;
224225
latch.countDown();
225226
});
226-
cosmosItemResponseMono.subscribe();
227+
Disposable d = cosmosItemResponseMono.subscribe();
227228
latch.await();
229+
d.dispose();
228230
return statusCode;
229231
}
230232
else
@@ -259,9 +261,9 @@ private int[] createDocument(JSONObject jsonObject, Object partitionKey) throws
259261
latch.countDown();
260262
});
261263

262-
cosmosItemResponseMono.subscribe();
264+
Disposable d = cosmosItemResponseMono.subscribe();
263265
latch.await();
264-
266+
d.dispose();
265267
return statusCode;
266268
} else {
267269
throw new Exception("CosmosDB Insert Execution failed. Invalid json payload.");
@@ -296,8 +298,9 @@ private int[] replaceDocument(JSONObject jsonObject, String idValue , Object par
296298
latch.countDown();
297299
});
298300

299-
cosmosItemResponseMono.subscribe();
301+
Disposable d = cosmosItemResponseMono.subscribe();
300302
latch.await();
303+
d.dispose();
301304
return statusCode;
302305
}
303306
else {

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<junit.version>4.13.2</junit.version>
2727
<com.amazonaws.version>1.12.376</com.amazonaws.version>
2828
<software.awssdk.version>2.17.272</software.awssdk.version>
29-
<software.azure.cosmos.version>4.41.0</software.azure.cosmos.version>
29+
<software.azure.cosmos.version>4.42.0</software.azure.cosmos.version>
3030
<log4j.version>2.19.0</log4j.version>
3131
<io.opentelemetry.version>1.19.0</io.opentelemetry.version>
3232
</properties>

0 commit comments

Comments
 (0)