Azure-cosmos-dotnet-v3: How to migrate from thread-safe DocumentClient`?

Created on 21 Nov 2019  路  3Comments  路  Source: Azure/azure-cosmos-dotnet-v3

I work on the migration from SDK v2 to SDK 3 in the performance-critical application.
In SDK v2, the recommendation was to use single DocumentClient across for all queries, even in parallel, since this class is thread-safe.

What is the recommendation for SDK v3? In the past we had DocumentClient, but now we have CosmosClient, Database and Container. From the samples I can see that I can reuse Container for multiple queries, but is it safe to do parallel queries on it?

According to the performance tips in https://docs.microsoft.com/en-us/azure/cosmos-db/performance-tips, only CosmosClient is thread-safe. Does it mean that I need to create single CosmosClient and a new Container every time when I need to do a query?

documentation

Most helpful comment

Thanks. I think it would be worth to clarify it somewhere, for example in https://docs.microsoft.com/en-us/azure/cosmos-db/performance-tips. For me, it sounds correct, but I wasn't sure.

All 3 comments

CosmosClient, database, and container are thread safe. For the best performance use the same Container for all the operations. Creating a new Container for each call will cause unnecessary overhead.

Thanks. I think it would be worth to clarify it somewhere, for example in https://docs.microsoft.com/en-us/azure/cosmos-db/performance-tips. For me, it sounds correct, but I wasn't sure.

@ausfeldt can you do the documentation update?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gegoodwin picture gegoodwin  路  7Comments

ealsur picture ealsur  路  6Comments

j82w picture j82w  路  4Comments

kirankumarkolli picture kirankumarkolli  路  7Comments

Liversage picture Liversage  路  7Comments