Partial updates main advantage is not saving R/U for transactions.
They will make update process easier. (You don't need send the whole document to Cosmos DB to update an item)
Some of the advantages are :
Also, it reduces network bandwidth since you don't send the whole document anymore.
lower end-toend latency
saves CPU cycles on the Azure Cosmos DB SDK client hosts.
Patch operation taking more RU's than replace. What gives?
I have the following document in a cosmos DB (running emulator).
{
"partitionKey": "3be5653d-c500-4a20-9f30-ce9df876c397",
"NumberOfRatings": 0,
"AverageRating": -1,
"Views": 2,
"Favorites": 0
}
The above gets updated many times, and according to my reading patching a document should be more optimal than replacing an entire document. I have run some tests with the following code. The first block patches a document the second replaces it. They both increment the Views count in the above document by 1:
// Gets a user in the database
UserInfo userInfo = GetUser();
// This operation costed 10,79 RU's
ItemResponse<UserInfo> response = await container.PatchItemAsync<UserInfo>(
id: userInfo.Id.ToString(),
partitionKey: new PartitionKey(userInfo.UserId.ToString()),
patchOperations: new[] {
PatchOperation.Increment("/Views", 1)
}
);
// This operation costed 10,67 RU's
response = await container.ReadItemAsync<UserInfo>(userInfo.Id.ToString(), new PartitionKey(userInfo.UserId.ToString()));
UserInfo itemBody = response.Resource;
itemBody.Views++;
response = await container.ReplaceItemAsync<UserInfo>(itemBody, itemBody.Id.ToString(), new PartitionKey(itemBody.UserId.ToString()));
The patching costed 10,79 RU's while the replacing costed 10,67 RU's. I would like to therefore ask the following two questions:
- Is this normal?
- If its normal, what the purpose of patching if it does not improve RU cost, rather makes it worse?
Azure Cosmos DB
-
Hasan Savran 331 Reputation points MVP
2022-07-11T15:31:37.373+00:00
1 additional answer
Sort by: Most helpful
-
Hasan Savran 331 Reputation points MVP
2022-07-12T18:22:12.29+00:00 I am glad this helped @Bubba Jones
For monitoring, I can reference the following article since it is a free way to do this.
https://stackify.com/w3wp-high-cpu-usage/