Elfocrash / Cosmonaut

🌐 A supercharged Azure CosmosDB .NET SDK with ORM support
https://cosmonaut.readthedocs.io
MIT License
342 stars 44 forks source link

Timeout or memory leak issue #99

Closed crhistianramirez closed 4 years ago

crhistianramirez commented 4 years ago

We are executing a very simple query on our production database but are seeing a timeout. When we run it locally the memory consumption goes up very high before timing out. In test this was no problem but we didn't have that many documents in there. The production collection is not insignificant but is not super big either, (about 500MB)

return await _cosmos.QueryMultipleAsync("SELECT * FROM c");

When we run this same query in the query explorer on azure it comes back almost instantly. Is there anything you can think of that might be causing such an issue? Is it incorrectly trying to paginate over all documents?

I would appreciate any assistance on this.

Elfocrash commented 4 years ago

This is totally expected. Your performing a cross partition query against all your documents. Cosmos DB is not designed to perform in this scenario. The explorer works because it returns 100 documents at a time. Cosmonaut abstracts the pagination away and return whatever you tell it to.

crhistianramirez commented 4 years ago

Ahh I see. So something like

_cosmos.Query("select * from c").WithPagination(1, 100).ToListAsync();

Might be what I'm looking for?

Elfocrash commented 4 years ago

If you want pagination then yeah. If you’re using the CosmosStore class then simply do _cosmosStore.Query().WithPagination(1, 100).ToListAsync.

Keep in mind however that this is still a cross partition query and it isn’t recommended. You should always use the partition key.

crhistianramirez commented 4 years ago

@Elfocrash thank you for your patience and assistance 🙇