cosmos-db
  1. cosmos-db-request-units-rus

Request Units (RUs) - CosmosDB Partitioning and Throughput

Overview

Request Units (RUs) are the currency used in Azure Cosmos DB to measure the resource consumption of database operations. When you issue a request to Azure Cosmos DB, the database engine processes that request and determines how many RUs are required to complete the operation.

Azure Cosmos DB needs to accurately calculate the number of RUs required for each operation in order to be able to ensure predictable performance and scalability. Partitioning is a key feature of Azure Cosmos DB that allows it to horizontally scale by distributing data across multiple physical partitions.

Syntax

The syntax for calculating the number of RUs required for a query or an operation is:

Request Units = (size of data returned / 1 KB) * RU factor

Where:

  • RU factor is a number that varies based on the operation being performed. For example, the RU factor for a query is typically higher than the RU factor for a read or write operation.
  • size of data returned is the amount of data returned by the query or operation, measured in bytes.

Example

Suppose you have a collection with a total size of 100 GB, and the collection is configured with a throughput of 10,000 RUs. If you issue a query that returns 1 MB of data and has an RU factor of 5, the number of RUs required would be:

Request Units = (1 MB / 1 KB) * 5 = 5 RUs

Output

The output of any query or operation in Azure Cosmos DB is the result set or the data that is returned by the query. The number of RUs required to process the query or operation is also returned in the response headers.

Explanation

Request Units are a measure of the machine resources that are consumed by a query or operation, including CPU, memory, network I/O, and storage I/O. Each query or operation requires a specific number of RUs, based on the complexity of the query and the amount of data returned.

The key to achieving optimal performance and scalability with Azure Cosmos DB is understanding how to partition your data effectively. By distributing your data across multiple physical partitions, you can maximize throughput and minimize latency.

Use

Understanding Request Units is important when you are designing your data model and choosing a partition key for your collections. By choosing an appropriate partition key, you can achieve a balanced distribution of data across partitions, which can help you avoid performance issues caused by hot partitions.

You can monitor the number of Request Units consumed by your queries and operations in the Azure Portal. By analyzing this data, you can identify queries that are consuming excessive resources and optimize your queries and indexes for better performance.

Important Points

  • Request Units are the currency used in Azure Cosmos DB to measure the resource consumption of database operations.
  • Azure Cosmos DB uses partitioning to horizontally scale by distributing data across multiple physical partitions.
  • The number of RUs required for a query or operation is calculated based on the size of data returned and the operation's RU factor.
  • Choosing an appropriate partition key is important for achieving optimal performance and avoiding hot partitions.
  • You can monitor your Request Unit consumption in the Azure Portal to identify inefficient queries or indexes.

Summary

Request Units are a key metric for optimizing the performance and scalability of Azure Cosmos DB. By understanding how RUs are calculated and how to choose an appropriate partition key, you can design a data model that can scale to meet your needs.

Published on: