简体   繁体   English

查询性能指标Cosmos DB

[英]Query performance measure Cosmos DB

Im new to Cosmos DB and i try to do some performance measurements for querying against a cosmos db collection (documentdb api) duo c#-sdk. 我是Cosmos DB的新手,我尝试做一些性能测量来查询cosmos db集合(documentdb API)duo c#-sdk。 I try to do it using a simple Stopwatch. 我尝试使用简单的秒表来做到这一点。 But when i query with the following code snipped, i always get fluctuating measurement data between 14ms and like 33ms. 但是,当我使用以下代码进行查询时,我总是会在14ms到33ms之间获得波动的测量数据。 Its independent if i query a record about one or 10000 data and also independent if i query against a partitionkey-value, another indexed value or a not indexed value with EnableScaninQuery active. 如果我查询有关一个或10000个数据的记录,它是独立的;如果我在EnableScaninQuery处于活动状态的情况下,对分区键值,另一个索引值或未索引值进行查询,则它也是独立的。 So i guess with this code is something wrong? 所以我想这段代码有问题吗? I expect very much higher time to collect 10000 records of unindexed data rather than querying one partitionkey data. 我希望有更多的时间来收集10000条未索引数据的记录,而不是查询一个分区键数据。 Also the FeedOptions provide the PopulateQueryMetrics method. FeedOptions还提供PopulateQueryMetrics方法。 Is there any way to get access to the querytime using this metrics in my c# application? 在我的C#应用​​程序中,有什么方法可以使用此指标来访问查询时间?

FeedOptions asd = new FeedOptions
        {
            EnableCrossPartitionQuery = true,
            // EnableScanInQuery = true,
            //PopulateQueryMetrics = true,
            MaxItemCount = 500,
            MaxBufferedItemCount = 10000,
            MaxDegreeOfParallelism = -1
        }; 
watch.Start();
            try
            {
                IDocumentQuery<Item> query = client.CreateDocumentQuery<Item>(
                    UriFactory.CreateDocumentCollectionUri(Database, coll), asd)
                    .Where(m => m.userid == 999999).AsDocumentQuery<Item>();

                WriteToConsoleAndPromptToContinue("Query took {0} ms ", watch.ElapsedMilliseconds);
                watch.Stop();

Try iterating through the whole result set to produce reliable results. 尝试遍历整个结果集以产生可靠的结果。

while (query.HasMoreResults)  
{
    var result = await query.ExecuteNextAsync<Item>();

    // Process paged results
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM