Azure Cosmos DB Emulator slow (100 ms / request)

844 views Asked by At

I am trying to set up the Azure Cosmos DB Emulator to work locally with integration tests but I found that it is very slow.

I am reading a ~1KB JSON document with the container.ReadItemAsync<T> method, and awaiting the answer. I am calling this method in a loop, for 100 times.

The execution time is consistently around 9.5-10 seconds, so one request takes around 100 milliseconds which is very slow compared to the fact that this service is running locally.

Why is this so slow and how can I make it faster?
I expect at most 1 ms / request considering it is all disk I/O.

I tried the following but they didn't work:

  • Turning Rate Limiting on/off
  • creating the database/collection with various provisioning settings, it has zero effect on performance (even 100k RU)
  • creating the db and collection manually vs with the client SDK
  • "Reset Data" menu in the emulator tray menu

Further information:

  • The emulator version is 2.14.6.0 (68d4ca59)
  • I start the emulator from the start menu, but starting it from the command line doesn't change anything
  • I am using the Microsoft.Azure.Cosmos nuget package, version 3.22.1
  • my CPU is i7-8565U, but it isn't even fully used while the test is running
  • my system has 16 GB RAM
  • my system is running on a fast enough SSD: "NVMe SK hynix BC501 H", but while running the test the SSD usage is between 0 and 2%.
  • the performance is the same if I increase the document size to 100 KB or even 1 MB.
1

There are 1 answers

0
Károly Ozsvárt On BEST ANSWER

Creating your CosmosClientOptions with the AllowBulkExecution = true setting can cause this.

the SDK will construct batches and group operations, when the batch is full, it will get dispatched, but if the batch doesn’t fill up, there is a timer that will dispatch it to make sure they complete. This timer currently is 100 milliseconds. So if the batch does not get filled up (for example, you are just sending 50 concurrent operations), then the overall latency might be affected.

Source: Introducing Bulk support in the .NET SDK