question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Not a bug but a query on why my code is slow

See original GitHub issue

A query loading all documents from a single partition on a container is very slow. 1481 documents, all of the same type. 6 MB of data takes between 1.5 seconds on my laptop with 200Mbps internet. Would I expect this query to be so slow?

This is a cut down version of the code:

            var requestOptions = new QueryRequestOptions()
            {
                MaxBufferedItemCount = -1,
                MaxItemCount = -1,
                PartitionKey = new PartitionKey(partitionKey.ToString()),
            };

            var setIterator = container
                .GetItemLinqQueryable<T>(false, requestOptions: requestOptions).ToFeedIterator();
            
            var list = new List<T>();

            while (setIterator.HasMoreResults)
            {
                var response = await setIterator.ReadNextAsync().ConfigureAwait(false);
                list.AddRange(response);
            }

            // takes 2 to 4 seconds to get here

The execution time is all spent running the ReadNextAsync function.

Here are query stats from the COSMOS page on Azure:

image

Thank you.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
simonzieglercommented, Oct 4, 2022

Will do and thank you

1reaction
ealsurcommented, Oct 3, 2022
using var response = await iterator.ReadNextAsync().ConfigureAwait(false);
Console.WriteLine(response.Diagnostics.ToString());

Reference: https://learn.microsoft.com/en-us/azure/cosmos-db/sql/troubleshoot-dot-net-sdk-slow-request?tabs=cpu-new#capture-diagnostics

Read more comments on GitHub >

github_iconTop Results From Across the Web

5 reasons why your code is running so slowly—and how to ...
Here's how to address why the code runs well on your development machine but has totally borked in production.
Read more >
sql server - Why would a query in code be slower than a ...
We are currently facing an issue where the same query executed in the code takes (on average) 15-20 seconds. The same query on...
Read more >
Query extremely slow in code but fast in SSMS
Both tables are well indexed and the execution plan in SSMS says they are using index seeks for the look-ups so they are...
Read more >
Troubleshoot slow-running queries - SQL Server
RUNNING: Queries can be slow because they're running (executing) for a long time. In other words, these queries are actively using CPU resources...
Read more >
Bug found. Causes whole website to slow down significantly
My client uses it a lot and they have a lot of IP addresses in it. However, recently we found that the website...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found