Priority-based execution in Azure Cosmos DB
APPLIES TO: NoSQL
Priority based execution allows users to specify priority of requests sent to Azure Cosmos DB. In cases where the number of requests exceeds the capacity that can be processed within the configured Request Units per second (RU/s), then Azure Cosmos DB throttles low priority requests to prioritize the execution of high priority requests.
This feature enables users to execute critical tasks while delaying less important tasks when the total consumption of container exceeds the configured RU/s in high load scenarios by implementing throttling measures for low priority requests first. Any client application using SDK retries low priority requests in accordance with the retry policy configured.
Note
Priority-based execution feature doesn't guarantee always throttling low priority requests in favor of high priority ones. This operates on best-effort basis and there are no SLA's linked to the performance of the feature.
Use-cases
You can use priority-based execution when your application has different priorities for workloads running on the same container. For example,
- Prioritizing read, write, or query operations.
- Prioritizing user actions vs background operations like
- Stored procedures
- Data ingestion/migration
Getting started
To get started using priority-based execution, navigate to the Features page in you're in Azure Cosmos DB account. Select and enable the Priority-based execution (preview) feature.
SDK requirements
- .NET v3: v3.33.0-preview or later
- Java v4: v4.45.0 or later
- Spark 3.2: v4.19.0 or later
- JavaScript v4: v4.0.0 or later
- Python: v4.5.2b2 or later. Available only in preview version.
Code samples
using Microsoft.Azure.Cosmos;
//update products catalog with low priority
RequestOptions catalogRequestOptions = new ItemRequestOptions{PriorityLevel = PriorityLevel.Low};
PartitionKey pk = new PartitionKey(“productId1”);
ItemResponse<Product> catalogResponse = await this.container.CreateItemAsync<Product>(product1, pk, requestOptions);
//Display product information to user with high priority
RequestOptions getProductRequestOptions = new ItemRequestOptions{PriorityLevel = PriorityLevel.High};
string id = “productId2”;
PartitionKey pk = new PartitionKey(id);
ItemResponse<Product> productResponse = await this.container.ReadItemAsync< Product>(id, pk, getProductRequestOptions);
Monitoring Priority-based execution
You can monitor the behavior of requests with low and high priority using Azure monitor metrics in Azure portal.
- Monitor Total Requests (preview) metric to observe the HTTP status codes and volume of low and high priority requests.
- Monitor the RU/s consumption of low and high priority requests using Total Request Units (preview) metric in Azure portal.
Change default priority level of a Cosmos DB account
If Priority-based execution is enabled and priority level isn't specified for a request by the user, then all such requests are executed with high priority. You can change the default priority level of requests in a Cosmos DB account using Azure CLI.
Azure CLI
# install preview Azure CLI version 0.26.0 or later
az extension add --name cosmosdb-preview --version 0.26.0
# set subscription context
az account set -s $SubscriptionId
# Enable priority-based execution
az cosmosdb update --resource-group $ResourceGroup --name $AccountName --enable-priority-based-execution true
# change default priority level
az cosmosdb update --resource-group $ResourceGroup --name $AccountName --default-priority-level low
Data explorer priority
When Priority-based execution is enabled for a Cosmos DB account, all requests in the Azure portal's Data Explorer are executed with low priority. You can adjust this by changing the priority setting in the Data Explorer's Settings menu.
Note
This client-side configuration is specific to the concerned user's Data explorer view only and won't affect other users' Data explorer priority level or the default priority level of the Cosmos DB account.
Limitations
Priority-based execution is currently not supported with following features:
- Serverless accounts
- Bulk execution API
The behavior of priority-based execution feature is nondeterministic for shared throughput database containers.
Next steps
- See the FAQ on Priority-based execution
- Learn more about Burst capacity
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for