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

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

Gremlin API 返回的标头将映射到目前由 Gremlin .NET 和 Java SDK 公开的自定义状态特性。Headers returned by the Gremlin API are mapped to custom status attributes, which currently are surfaced by the Gremlin .NET and Java SDK. 请求费用显示在 x-ms-request-charge 键下。The request charge is available under the x-ms-request-charge key. 使用 Gremlin API 时,可以通过多个选项来查找针对 Azure Cosmos 容器执行的操作所消耗的 RU。When you use the Gremlin API, you have multiple options for finding the RU consumption for an operation against an Azure Cosmos container.

使用 Azure 门户Use the Azure portal

  1. 登录到 Azure 门户Sign in to the Azure portal.

  2. 创建新的 Azure Cosmos 帐户并在其中植入数据,或选择一个已包含数据的现有帐户。Create a new Azure Cosmos account and feed it with data, or select an existing account that already contains data.

  3. 转到“数据资源管理器”窗格,然后选择要处理的容器。Go to the Data Explorer pane, and then select the container you want to work on.

  4. 输入有效的查询,然后选择“执行 Gremlin 查询”。Enter a valid query, and then select Execute Gremlin Query.

  5. 选择“查询统计信息”,以显示执行的请求的实际请求费用。Select Query Stats to display the actual request charge for the request you executed.

在 Azure 门户中获取 Gremlin 查询请求费用的屏幕截图

使用 .NET SDK 驱动程序Use the .NET SDK driver

使用 Gremlin .NET SDK 时,状态特性将显示在 ResultSet<> 对象的 StatusAttributes 属性下:When you use the Gremlin.NET SDK, status attributes are available under the StatusAttributes property of the ResultSet<> object:

ResultSet<dynamic> results = client.SubmitAsync<dynamic>("g.V().count()").Result;
double requestCharge = (double)results.StatusAttributes["x-ms-request-charge"];

有关详细信息,请参阅快速入门:使用 Azure Cosmos DB Gremlin API 帐户生成 .NET Framework 或 Core 应用程序For more information, see Quickstart: Build a .NET Framework or Core application by using an Azure Cosmos DB Gremlin API account.

使用 Java SDK 驱动程序Use the Java SDK driver

使用 Gremlin Java SDK 时,可以通过对 ResultSet 对象调用 statusAttributes() 方法来检索状态特性:When you use the Gremlin Java SDK, you can retrieve status attributes by calling the statusAttributes() method on the ResultSet object:

ResultSet results = client.submit("g.V().count()");
Double requestCharge = (Double)results.statusAttributes().get().get("x-ms-request-charge");

有关详细信息,请参阅快速入门:使用 Java SDK 在 Azure Cosmos DB 中创建图形数据库For more information, see Quickstart: Create a graph database in Azure Cosmos DB by using the Java SDK.

后续步骤Next steps

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