RU Consumption is Unaffected when using Gateway Cache and Consistency Level Session
See original GitHub issueDescribe the bug Using Microsoft.Azure.Cosmos version 3.23.0-preview, when the CosmosClient is generated if it uses CosmosClientOptions.ConsistencyLevel = ConsistencyLevel.Session duplicate queries will not reduce the RU cost whatsoever, however it will reduce the RU cost to 0 if using ConsistencyLevel.Eventual.
To Reproduce Create a CosmosClient pointing to a CosmosDB resource with gateway caching enabled with the following options:
new CosmosClient({yourUri},
{yourAuthKey},
new CosmosClientOptions
{
ConnectionMode = ConnectionMode.Gateway,
ConsistencyLevel = ConsistencyLevel.Session
});
Then write a query against any database and container. Run the query more than once and check the FeedResponse.RequestCharge every time. Every time the query is executed RUs are charged against the account. Now create a ComosClient with the following options:
new CosmosClient({yourUri},
{yourAuthKey},
new CosmosClientOptions
{
ConnectionMode = ConnectionMode.Gateway,
ConsistencyLevel = ConsistencyLevel.Eventual
});
Repeat the steps above and you’ll see that after the first request the RU charge drops down to 0 for subsequent requests.
Expected behavior According to this documentation: https://docs.microsoft.com/en-us/azure/cosmos-db/how-to-configure-integrated-cache#adjust-request-consistency
The integrated cache should be utilized if the ConsistencyLevel is Eventual or Session
Actual behavior The integrated Cache appears to be being bypassed when the ConsistencyLevel is Session
Environment summary SDK Version: 3.23.0-preview OS Version Windows
Additional context Additionally, you may want to consider not exposing CosmosClient.ClientOptions.ConnectionMode and CosmosClient.ClientOptions.ConsistencyLevel because if those variables are not set in the constructor for CosmosClient they seem to be ignored and that can be quite confusing.
Issue Analytics
- State:
- Created 2 years ago
- Comments:13 (6 by maintainers)
Top GitHub Comments
I will email you our CosmosDB name but I’m including the sample code here for reference in the event others experience this issue.
This is run in Linqpad, if you run the above code twice you will be charged RU’s both times, but if you set the consistencyLevel to eventual and run the code twice you will only be charged for the first request.
@ealsur I see, that does make sense and thank you for the explanation. If that is the case I would appreciate any help directing me to whom I should make a bug report.