【发布时间】:2016-02-06 12:07:05
【问题描述】:
鉴于 Azure DocumentDB 使用请求单位作为吞吐量的衡量标准,我想确保我的查询使用尽可能少的 RU 来提高吞吐量。是否有工具可以告诉我一个查询需要多少 RU,以及查询是否实际使用索引?
【问题讨论】:
标签: azure query-performance azure-cosmosdb
鉴于 Azure DocumentDB 使用请求单位作为吞吐量的衡量标准,我想确保我的查询使用尽可能少的 RU 来提高吞吐量。是否有工具可以告诉我一个查询需要多少 RU,以及查询是否实际使用索引?
【问题讨论】:
标签: azure query-performance azure-cosmosdb
如您所见,某些工具会在完成查询后提供 RU。这也可以通过编程方式获得,因为x-ms-request-charge 标头会在响应中返回,并且可以通过 DocumentDB SDK 轻松检索。
例如,这是一个显示使用 JS/node 检索 RU 的 sn-p:
var queryIterator = client.queryDocuments(collLink, querySpec );
queryIterator.executeNext(function (err, results, headers) {
if (err) {
// deal with error...
} else {
// deal with payload...
var ruConsumed = headers['x-ms-request-charge'];
}
});
至于您关于索引的问题,以及确定属性是否被索引(然后应该回答您关于使用或不使用索引的查询的问题):您可以查询集合,它会在响应中返回索引详细信息标题。
例如:给定一些路径dbs/<databaseId>/colls/<collectionId>:
var collLink = 'dbs/' + databaseId+ '/colls/'+ collectionId;
client.readCollection(collLink, function (err, coll) {
if (err) {
// deal with error
} else {
// compare indexingPolicy with your property, to see if it's included or excluded
// this just shows you what these properties look like
console.log("Included: " + JSON.stringify(coll.indexingPolicy.includedPaths))
console.log("Excluded: " + JSON.stringify(coll.indexingPolicy.excludedPaths))
}
});
您会看到 includedPaths 和 excludedPaths 看起来像这样,然后您可以以任何您认为合适的方式搜索给定的属性:
Included: [{"path":"/*","indexes":[{"kind":"Range","dataType":"Number","precision":-1},{"kind":"Hash","dataType":"String","precision":3}]}]
Excluded: []
【讨论】:
我找到了DocumentDb Studio,它显示了在每个查询中提供 RU 的响应标头。
【讨论】:
executeNext()),则每次调用都会出现 RU,因此您需要将它们相加以考虑所有 RU。我的 documentdb-utils 包装了 Azure 提供的 node.js SDK 以执行诸如总结所有 RU、为您提供延迟统计信息以及在操作超时或达到您的 RU 预算时自动重试操作。我已经考虑将库移植到 .NET。
另一种选择是使用模拟器并打开跟踪收集选项。 https://docs.microsoft.com/en-us/azure/cosmos-db/local-emulator
我试图分析 LINQ 聚合查询,目前这似乎用 c# SDK 是不可能的。
使用模拟器的跟踪输出,我能够识别请求费用和许多其他指标。有很多数据需要遍历。
我发现存储在此事件键下的请求费用
DocDBServer/Transport_Channel_Processortask/Genericoperation
示例输出:ThreadID="141,928" FormattedMessage="EndRequest DocumentServiceId localhost, ResourceType 2, OperationType 15, ResourceId 91M7AL+QPQA=, StatusCode 200, HRESULTHex 0, ResponseLength 61, Duration 70,546, HasQuery 1, PartitionId a4cb495b-38c8-11e6-8106-8cdcd42c33be, ReplicaId 1, ConsistencyLevel 3, RequestSessionToken 0:594, ResponseSessionToken 594, HasContinuation 0, HasPreTrigger 0, HasPostTrigger 0, IsFeedUnfiltered 0, IndexingDirective 5, XDate Fri, 09 Jun 2017 08:49:03 GMT, RetryAfterMilliseconds 0, MaxItemCount -1, ActualItemCount 1, ClientVersion 2017-02-22, UserAgent Microsoft.Azure.Documents.Common/1.13.58.2, RequestLength 131, NetworkBucket 2, SubscriptionId 00000000-0000-0000-0000-000000000000, Region South Central US, IpAddress 192.168.56.0, ChannelProtocol RNTBD, RequestCharge 51.424, etc...
然后可以将其与来自另一个包含查询信息的事件的数据相关联:
DocDBServer/ServiceModuletask/Genericoperation
请注意,您需要 perfview 才能查看 ETL 日志文件。请参阅此处了解更多信息: https://github.com/Azure/azure-documentdb-dotnet/blob/master/docs/documentdb-sdk_capture_etl.md
【讨论】: