spring-data-cosmosdb icon indicating copy to clipboard operation
spring-data-cosmosdb copied to clipboard

spring-data-cosmosdb Read/Write latency issue

Open linux-code opened this issue 4 years ago • 3 comments

Hi, Can someone help me to understand below issue-

Observing [60-120] ms response time for one read call (service to cosmos-db): Using below client and configuration-

  1. spring-data-cosmosdb (2.3.0) with sync API(@EnableCosmosRepositories)
  2. Not using any cross-partition Query.
  3. Connection Mode- GATEWAY
  4. DEFAULT_MAX_POOL_SIZE = 100;
  5. DEFAULT_IDLE_CONNECTION_TIMEOUT_IN_MILLIS = 60 * 1000;
  6. Server and CosmosDB are in the same geographical location.
  7. SESSION consistency policy.
  8. Document is flat and small in size.

As per cosmosDB documentation - Read call takes <= 10 ms and Write call takes <=15 ms

According to above metrics, my client is taking 12 times greater than above time(10 ms) in worst case.

Could you please let me know, is this expected behaviour or I am missing some configuration here. Do you have any metrics which shows latency vs configuration factors for sync/reactive repository.

Note- I have tried to change Connection Mode to DIRECT Mode(as per best practices recommendation), but getting resources are no longer available warning. Is this mode supported in spring-data-cosmosdb (2.3.0)?

linux-code avatar Jun 08 '20 20:06 linux-code

@linux-code DIRECT mode is supported in spring-data-cosmosdb v2.3.0, in fact that is the default connection mode. CosmosDB does not provide any SLAs for GATEWAY mode. Since GATEWAY is a shared resource, some calls may take a little longer because of heavy traffic.

Sync / Async repository uses the same code for the implementation, so the metrics should be similar. Since sync code uses blocking calls, the throughput will be affected, but latency should not get much affected.

That being said, what is the query targeting ? (id, partition key, or indexed fields ) ? What errors are you seeing in DIRECT mode ?

kushagraThapar avatar Jun 25 '20 16:06 kushagraThapar

Thank you for your update Kushagra.

  1. Sync / Async repository uses the same code for the implementation, so the metrics should be similar. Since sync code uses blocking calls, the throughput will be affected, but latency should not get much affected. Agree with you

  2. That being said, what is the query targeting ? This is simple read query using id and Partition-key with default indexing on all fields. Sometimes query is getting completed within 5 ms best case , 40 ms avg case and 120 ms in worst case in GATEWAY mode. Also checked cosmos query monitoring logs , found the same, cosmos db server has taken nearly same time. I am sure, this is not spring-data-cosmosdb issue.

  3. What errors are you seeing in DIRECT mode ? I am able to connect with direct mode (able to run app successfully) but when I am hitting any API to read/write the document then at this time i am getting resources are no longer available but the same API is working fine with GATEWAY mode.

linux-code avatar Jul 21 '20 07:07 linux-code

@linux-code Can you please share the stack trace for resources are no longer available issue ?

kushagraThapar avatar Jul 22 '20 17:07 kushagraThapar