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

适用于: Cassandra 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 Cassandra 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 Cassandra API. 如果你使用其他 API,请参阅 MongoDB APISQL APIGremlin API表 API 文章来查找每秒的 RU 费用。If you are using a different API, see API for MongoDB, SQL API, Gremlin API, and Table API articles to find the RU/s charge.

针对 Azure Cosmos DB Cassandra API 执行操作时,RU 费用将在传入的有效负载中以名为 RequestCharge 的字段形式返回。When you perform operations against the Azure Cosmos DB Cassandra API, the RU charge is returned in the incoming payload as a field named RequestCharge. 可以使用多个选项来检索 RU 费用。You have multiple options for retrieving the RU charge.

使用 .NET SDKUse the .NET SDK

使用 .NET SDK 时,可以在 RowSet 对象的 Info 属性下检索传入的有效负载:When you use the .NET SDK, you can retrieve the incoming payload under the Info property of a RowSet object:

RowSet rowSet = session.Execute("SELECT table_name FROM system_schema.tables;");
double requestCharge = BitConverter.ToDouble(rowSet.Info.IncomingPayload["RequestCharge"].Reverse().ToArray(), 0);

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

使用 Java SDKUse the Java SDK

使用 Java SDK 时,可以通过对 ResultSet 对象调用 getExecutionInfo() 方法来检索传入的有效负载:When you use the Java SDK, you can retrieve the incoming payload by calling the getExecutionInfo() method on a ResultSet object:

ResultSet resultSet = session.execute("SELECT table_name FROM system_schema.tables;");
Double requestCharge = resultSet.getExecutionInfo().getIncomingPayload().get("RequestCharge").getDouble();

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

后续步骤Next steps

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