Determine query cost in Gremlin.NET on Comos DB

I found it hard to find the query cost when using Gremlin.NET on Cosmos DB.

The only way I found until now is to analyse the exception text when a RequestRateTooLargeException is thrown.

Typically the most resource intensive queries throw these exceptions so it is interesting to analyse the query costs for these specific queries.

ServerError:
ActivityId : 3ae242d9-09bd-4870-8e0c-5f3b56941726
ExceptionType : RequestRateTooLargeException
ExceptionMessage :
 Message: {"Errors":["Request rate is large"]}
 ActivityId: 3f4d0f5c-a776-4f41-ab9c-ee9f08d64ca4, Request URI:, RequestStats:
 ResponseTime: 2018-03-26T06:57:58.4519869Z, StoreReadResult: StorePhysicalAddress: , GlobalCommittedLsn: 7393074, PartitionKeyRangeId: , IsValid: True, StatusCode: 0, IsGone: False, IsNotFound: False, IsInvalidPartition: False, RequestCharge: 0.38, ItemLSN: -1, ResourceType: Document, OperationType: Query
 , SDK: documentdb-dotnet-sdk/1.20.0 Host/64-bit MicrosoftWindowsNT/6.2.9200.0
Source : Microsoft.Azure.Documents.ClientMessage: {"Errors":["Request rate is large"]}
ActivityId: 3f4d0f5c-a776-4f41-ab9c-ee9f08d64ca4, Request URI: /, RequestStats:
ResponseTime: 2018-03-26T06:57:58.4519869Z, StoreReadResult: StorePhysicalAddress: , LSN: 7393075, GlobalCommittedLsn: 7393074, PartitionKeyRangeId: , IsValid: True, StatusCode: 0, IsGone: False, IsNotFound: False, IsInvalidPartition: False, RequestCharge: 0.38, ItemLSN: -1, ResourceType: Document, OperationType: Query
, SDK: documentdb-dotnet-sdk/1.20.0 Host/64-bit MicrosoftWindowsNT/6.2.9200.0
 BackendStatusCode : 429
 BackendActivityId : 3f4d0f5c-a776-4f41-ab9c-ee9f08d64ca4
 HResult : 0x80131500

I get the request charge out of the exception in the following way

   try
               {
                    var results = await _gremlinClient.SubmitAsync(query);
                    
                    return results;
                }
                catch (ResponseException r)
                {
                    if (r.Message.Contains("Request rate is large"))
                    {
                        Regex queryCostFinder = new Regex(@"RequestCharge: (\d{1,5}\.\d{1,4})");
                        var match = queryCostFinder.Match(r.Message);
                        queryCosts = double.Parse(match.Groups[1].Value);
                    }
                    else
                        throw;
                }

It helps but you rather see a property in Gremlin.NET that returns this value from the Http request charge header so you know it for all requests. I did not find a solution yet to fetch this header by using Gremlin.NET

Comments

Popular posts from this blog

System.Net.Http dll version problems

SharePoint Survey Back Button

How to set up AD FS for a development machine