Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to calculate the Azure Cosmos DB RU used in server side scripting

If I write a javascript store procedure in cosmos db and I loop through 1000 document and each doc is 1K size, does it cost me 1000 RU?

like image 444
David Chen Avatar asked Mar 07 '23 18:03

David Chen


1 Answers

RU calculation doesn't work like that (eg you cannot simply assume 1K doc x 1000 = 1000 RU).

The most accurate way of determining the cost of your stored procedure is to examine the RU charge, which is returned in the headers following the call to the stored procedure.

The header is x-ms-request-charge and is exposed via the returned headers in the SDK calls as well as raw REST calls.

In node/javascript, you'd make a call that looks something like:

client.executeStoredProcedure(sprocLink,params,options, function (err, doc, headers) {
  ...
})

You'd want to look at headers['x-ms-request-charge'].

like image 153
David Makogon Avatar answered Mar 10 '23 07:03

David Makogon