Issue with async Python SDK for Cosmos DB (SQL)

Obrad Simic 5 Reputation points
2023-03-10T17:01:45.89+00:00

Hi all,

I am using azure.cosmos.aio.CosmosClient from azure-cosmos=4.3.1 in my project.

I created a singleton client for better performances:

  • instantiate CosmosClient once with retry policy
  • call get_database_client once (I use one database in project)
  • for every request, obtain new container proxy, use it for a query (mostly read) and close it

My retry policy looks like this:


COSMOS_RETRY_POLICY = {    
    "request_timeout": 2000,    
    "retry_read": 10,   
    "retry_connect": 10,    
    "retry_total": 10,    
    "retry_status": 10
}

So the issue occurs when number of requests is around 60 per minute (around 30 failures in half hour).

For some requests, I receive status 500 with aiohttp.client_exceptions.ServerTimeoutError as response.

So my questions are:

  1. What is the maximum number of simultaneous requests which Cosmos DB can handle?
  2. Is there a way to configure connection pool for client?
  3. How should retry policy look like for higher loads (10 requests/second)?
  4. Would introducing dedicated gateway help?
Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,901 questions
{count} vote

2 answers

Sort by: Most helpful
  1. Obrad Simic 5 Reputation points
    2023-03-13T13:52:18.4933333+00:00

    httpx can not work after all, I am not able to handle requests with enable_cross_partition_query set to true


  2. Obrad Simic 5 Reputation points
    2023-03-21T14:52:55.43+00:00

    Hello Geetha,

    After further investigation, I figured that issue is caused by aiohttp

    Traceback (most recent call last):
      
    File "/usr/local/lib/python3.10/site-packages/aiohttp/connector.py", line 980, in _wrap_create_connection
        return await self._loop.create_connection(*args, **kwargs)  # type: ignore[return-value]  # noqa
      
    File "/usr/local/lib/python3.10/asyncio/base_events.py", line 1103, in create_connection
        transport, protocol = await self._create_connection_transport(
      
    File "/usr/local/lib/python3.10/asyncio/base_events.py", line 1133, in _create_connection_transport
        await waiter
    asyncio.exceptions.CancelledError
    During handling of the above exception, another exception occurred:
    

    Any idea on how to fix this?

    More info about server:

    • Containers are not big, the biggest one contains around 50k items
    • Provisioned throughput is 2000 RU/s (manual), and we use around 40% of that in peak
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.