azure-sdk-for-python icon indicating copy to clipboard operation
azure-sdk-for-python copied to clipboard

CosmosCLient sample with connection pooling

Open prashanthmadi opened this issue 5 years ago • 6 comments

Is your feature request related to a problem? Please describe. Looking for a cosmosdb sample to utilize connection pools couldn't find any at https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/cosmos/azure-cosmos/samples

prashanthmadi avatar Mar 08 '21 20:03 prashanthmadi

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @southpolesteve, @zfoster

ghost avatar Mar 08 '21 20:03 ghost

@annatisch Can someone familiar with core-http answer this question? Cosmos doesn't expose any knobs on HTTP connection pools AFAIK. We just use whatever defaults core-http provides.

southpolesteve avatar Mar 08 '21 22:03 southpolesteve

Hi @prashanthmadi, @southpolesteve - sorry I somehow missed this. Let me take a look today.

annatisch avatar Mar 18 '21 18:03 annatisch

Hi @prashanthmadi - you should be able to supply your own underlying Requests session to the client in order to handle connection pooling - as is documented in this issue here: https://github.com/Azure/azure-sdk-for-python/issues/12102#issuecomment-645641481

Let me know how this goes :) You're right in that we don't have a sample for this - but given that it is a feature universal to our (recent) SDKs, we would likely document/sample this feature in a common way, rather than write a specific sample for it for every SDK that supports it.

annatisch avatar Mar 18 '21 19:03 annatisch

I noticed the Java and .net CosmosClient suggest using CosmosClient as a singleton to improve performance. Is the python CosmosClient threadsafe or is that what supplying a Requests session would allow (apologies I’m new to python).

My situation is I’m using the python CosmosClient in azure functions. I’m creating a new CosmosClient in each request and seeing metadata fetches for every invocation which is impacting performance.

graemefoster avatar Mar 23 '21 00:03 graemefoster

Closing due to inactivity. Please reopen if this is still an issue.

gahl-levy avatar Nov 30 '21 18:11 gahl-levy