查找 Azure Cosmos DB 表 API 中执行的操作的请求单位费用Find the request unit charge for operations executed in Azure Cosmos DB Table API

适用于: 表 API

Azure Cosmos DB 支持多种 API,例如 SQL、MongoDB、Cassandra、Gremlin 和表。Azure Cosmos DB supports many APIs, such as SQL, MongoDB, Cassandra, Gremlin, and Table. 每个 API 具有自身的数据库操作集。Each API has its own set of database operations. 这些操作包括简单的点读取和写入,以及复杂的查询等等。These operations range from simple point reads and writes to complex queries. 每个数据库操作根据其复杂性消耗系统资源。Each database operation consumes system resources based on the complexity of the operation.

所有数据库操作的成本将由 Azure Cosmos DB 规范化,并以“请求单位”(简称 RU)表示。The cost of all database operations is normalized by Azure Cosmos DB and is expressed by Request Units (or RUs, for short). 你可以将 RU 视为性能货币,它抽象化了执行 Azure Cosmos DB 支持的数据库操作所需的系统资源,例如 CPU、IOPS 和内存。You can think of RUs as a performance currency abstracting the system resources such as CPU, IOPS, and memory that are required to perform the database operations supported by Azure Cosmos DB. 不管使用哪个 API 来与 Azure Cosmos 容器和数据库操作交互,都始终以 RU 来计量成本。No matter which API you use to interact with your Azure Cosmos container, costs are always measured by RUs. 无论数据库操作是写入、点读取还是查询,都始终以 RU 来计量成本。Whether the database operation is a write, point read, or query, costs are always measured in RUs. 若要了解详细信息,请参阅请求单位及其注意事项一文。To learn more, see the request units and it's considerations article.

本文介绍如何通过不同的方式来查找针对 Azure Cosmos DB 表 API 中的容器执行的任何操作所消耗的请求单位 (RU)。This article presents the different ways you can find the request unit (RU) consumption for any operation executed against a container in Azure Cosmos DB Table API. 如果你使用的是其他 API,请参阅 API for MongoDBCassandra APIGremlin APISQL API 这几篇文章来查找 RU/秒费用。If you are using a different API, see API for MongoDB, Cassandra API, Gremlin API, and SQL API articles to find the RU/s charge.

使用 .NET SDKUse the .NET SDK

目前,唯一能够返回表操作 RU 费用的 SDK 是 .NET 标准 SDKCurrently, the only SDK that returns the RU charge for table operations is the .NET Standard SDK. TableResult 对象公开 RequestCharge 属性,针对 Azure Cosmos DB 表 API 使用该 SDK 时,该 SDK 会填充该属性:The TableResult object exposes a RequestCharge property that is populated by the SDK when you use it against the Azure Cosmos DB Table API:

CloudTable tableReference = client.GetTableReference("table");
TableResult tableResult = tableReference.Execute(TableOperation.Insert(new DynamicTableEntity("partitionKey", "rowKey")));
if (tableResult.RequestCharge.HasValue) // would be false when using Azure Storage Tables
{
    double requestCharge = tableResult.RequestCharge.Value;
}

有关详细信息,请参阅快速入门:使用 .NET SDK 和 Azure Cosmos DB 生成表 API 应用For more information, see Quickstart: Build a Table API app by using the .NET SDK and Azure Cosmos DB.

后续步骤Next steps

若要了解如何优化 RU 消耗量,请参阅以下文章:To learn about optimizing your RU consumption, see these articles: