简体   繁体   中英

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. 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. 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. 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. Also the FeedOptions provide the PopulateQueryMetrics method. Is there any way to get access to the querytime using this metrics in my c# application?

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
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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