Find the request unit charge for operations executed in Azure Cosmos DB for Gremlin


Azure Cosmos DB supports many APIs, such as SQL, MongoDB, Cassandra, Gremlin, and Table. 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.

The cost of all database operations is normalized by Azure Cosmos DB and is expressed by Request Units (or RUs, for short). Request charge is the request units consumed by all your database operations. 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. No matter which API you use to interact with your Azure Cosmos container, costs are always measured by RUs. 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.

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 for Gremlin. 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.

Headers returned by the Gremlin API are mapped to custom status attributes, which currently are surfaced by the Gremlin .NET and Java SDK. The request charge is available under the x-ms-request-charge key. When you use the Gremlin API, you have multiple options for finding the RU consumption for an operation against an Azure Cosmos container.

Use the Azure portal

  1. Sign in to the Azure portal.

  2. 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. 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.

Screenshot to get a Gremlin query request charge in the Azure portal

Use the .NET SDK driver

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"];

For more information, see Quickstart: Build a .NET Framework or Core application by using an Azure Cosmos DB for Gremlin account.

Use the Java SDK driver

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");

For more information, see Quickstart: Create a graph database in Azure Cosmos DB by using the Java SDK.

Next steps

To learn about optimizing your RU consumption, see these articles: