'Cosmos Query Latency

FeedResponse<T> feedResponse =
cosmosContainer.readMany(
    ids.stream()
        .map(id -> new CosmosItemIdentity(partitionKey, id))
        .collect(Collectors.toList()),
    domainClass);

The above cosmos piece is taking more than 1 sec, which is too much. Is there any way to optimize it?



Solution 1:[1]

The latency of the code block execution depends on a few factors like:

  1. Where the code is being deployed: is it on your local machine or on Azure resources?
  2. If the code is on Azure resources, make sure to check the region of execution because a few regions will run with some latency in unexpected situations.
  3. Make sure to have the Cosmos DB created in the same region as that of execution. Latency will be high when the operation involves multiple regions.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 nathan liang