httpx
can not work after all, I am not able to handle requests with enable_
cross
_
partition
_query
set to true
Issue with async Python SDK for Cosmos DB (SQL)
Obrad Simic
5
Reputation points
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:
- What is the maximum number of simultaneous requests which Cosmos DB can handle?
- Is there a way to configure connection pool for client?
- How should retry policy look like for higher loads (10 requests/second)?
- Would introducing dedicated gateway help?
Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,901 questions
2 answers
Sort by: Most helpful
-
Obrad Simic 5 Reputation points
2023-03-13T13:52:18.4933333+00:00 -
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