Closed rislanov closed 4 years ago
Hi @rislanov, Thanks for providing us such detailed info! It is always recommended to reuse CloudTableClient. CloudTableClient is thread-safe. Here is some tips: https://azure.microsoft.com/en-us/blog/performance-tips-for-azure-documentdb-part-1-2/. It is for DocumentClient and some of it are applied to CloudTableClient as well.
Anyway, if we will use old SDK and CloudTableClient for Azure Table Storage, there will be no leaks with "client per request strategy":
So it seems to me, it looks like a bug :)
Hi @rislanov. Thanks again. So let's split the problem into 2 parts:
With regards to the guidance on reusing cloud table client across requests, how would you advise managing that in a scenario where you have to connect to multiple different storage accounts and the connection configuration changes per request? This a scenario we face using table storage.
@VIPHercules If you have multiple accounts, then you would need that many CloudTableClient instances. Each cloudtableinstance accepts a connection string/storage URI. However, within an account the need to create a cloud table client per request does not seem feasible, and will lead to memory leaks and other overhead issues described here.
closing as all questions have been answered on the issue. Please re-open if needed.
Is still holds to create singleton per domain for the latest Cosmos Table API client?
Hello!
We've tried to create a new instance of CloudTableClient per each request to storage (AddTransient in IoC container, for example) and it caused a memory leak.
So, after only a 500 requests to storage, we have a disproportional memory consuption:
But if we will use a single instance of CloudTableClient, everything will be ok:
The reason of this problem is that CloudTableClient doesn't call Dispose() for internal instance of Microsoft.Azure.Documents.Client.DocumentClient and there is no way to do it outside:
So it looks like the only one way to work with CloudTableClient is to use it as a singleton. But, in this case, it would be great to know exactly, that CloudTableClient is thread-safe :) Could you please confirm this?