So I have been doing a deep dive into Azure CosmosDB for a project. One of my objectives was to learn its performance characteristics when uploading a few million records an hour, and doing a cost analysis of CosmosDB vs other technologies already in use. I put together an app that's able to push a few hundred records in at an acceptable rate. So I do what I inevitably always do. From my laptop on hotel internet, I "dial it up to 11, and see what brakes", what could go wrong?
Well, it worked, and as expected, throttled when it hit the RU (Request Unit) limit. I increased the RU allocation, and it pushed more documents per second. Cool? NO, I was pushing 10,000+ RU/s and only getting a few hundred documents a second. So I did what I should have done to start with, ran the sample from a VM in the same datacenter as my DB. BINGO, it easily surpassed 1,000 documents per second. But for the same RU/s?
What's going on? Well after a bit of testing, I suspect that the RU calculation is primarily, if not exclusively, a function of time between when you open that socket and you get the "200 OK" back. That includes how long it takes you to send the data. Meaning that 10 MBs of documents sent at 1MB/s will be many times more expensive than the same documents sent at 1GB/s.
So what do we do about this? It's another factor you need to consider when selecting your replica data centers. And you may get more than just lower latency on writes when using a "follow the sun" strategy with your master node.
Well, it worked, and as expected, throttled when it hit the RU (Request Unit) limit. I increased the RU allocation, and it pushed more documents per second. Cool? NO, I was pushing 10,000+ RU/s and only getting a few hundred documents a second. So I did what I should have done to start with, ran the sample from a VM in the same datacenter as my DB. BINGO, it easily surpassed 1,000 documents per second. But for the same RU/s?
What's going on? Well after a bit of testing, I suspect that the RU calculation is primarily, if not exclusively, a function of time between when you open that socket and you get the "200 OK" back. That includes how long it takes you to send the data. Meaning that 10 MBs of documents sent at 1MB/s will be many times more expensive than the same documents sent at 1GB/s.
TL;DR : CosmosDB Request units are highly susceptible to connection latency. So under load, even the latency between an Azure data center in Europe and the US will increase your RU/s used by a small amount.
So what do we do about this? It's another factor you need to consider when selecting your replica data centers. And you may get more than just lower latency on writes when using a "follow the sun" strategy with your master node.