question

AnitaErnszt-7766 avatar image
0 Votes"
AnitaErnszt-7766 asked OuryBa-MSFT commented

Cosmos DB read performance is very slow

I'm trying to use Cosmos DB as a key-value store, and read the data from Function App. In case no data is found, the app should write the data into Cosmos DB.

My Function App and Cosmos DB both located in UK South.

I have set /id as partition key, and the keys being used as id. The ids are usually a few characters long, very max 40 byte.
The stored values are longer (1-1.5kb).

The read responses are rather slow (100-500ms, with around 250ms being the average). This performance result only reflects the db query itself, not the whole function.
According to the docs here https://docs.microsoft.com/en-us/azure/cosmos-db/how-to-model-partition-example read item should be ~2ms, so I'm lost where the performance difference is coming from.

I'm using python for the query, following the python cosmos db documentation:
container.read_item(id, partition_key=id)

azure-functionsazure-cosmos-db
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @AnitaErnszt-7766 Thank you for posting your question. Could you please the query used? Do you have a where clause in your query.? Majority of queries should contain partition key in the where clause.

Regards,
Oury

0 Votes 0 ·

Hello. I'm using the Python SDK and I followed the following example: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/cosmos/azure-cosmos/samples/document_management.py#L41-L49

My query look like this: container.read_item(id, partition_key=id)

I can only presume that the library is correctly using the where clause.

0 Votes 0 ·

1 Answer

mstaelen avatar image
0 Votes"
mstaelen answered OuryBa-MSFT commented

Hi @AnitaErnszt-7766,
have you looked at the indexing ? https://docs.microsoft.com/en-us/azure/cosmos-db/mongodb-indexing
regards,
Matthieu

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hello,

I've created the Cosmos DB with the Core API, as it's marked as recommended.

0 Votes 0 ·

@AnitaErnszt-7766 If you run with query statistics on that should give you info on exactly what happened within the Cosmos engine- what it did and how long it took. Any missing indexes would show up as scans in the statistics.

Regards,
Oury

0 Votes 0 ·