OrleansContrib/Orleans.CosmosDB

Request charge and stored procedures

Ulriksen opened this issue · 6 comments

As part of our scaling efforts we are looking at our CosmosDB utilization and costs. We noticed the procedure calling JSON.parse and wanted to see if we could send the extracted values (graintype, id and etag) as parameters instead of parsing it, and how this would affect the request charge (RC). Short version it doesn't.

We did however find the RU cost somewhat high compared to calling Cosmos operations directly. Based on the document below[1], here's our findings

Average RC read using stored procedure: 5.63
Average RC create using stored procedure: 11.68
Average RC update using stored procedure: 14.89

RC read using GET: 1
RC create using PUT: 6.29
RC update using POST: 10.29

This seems rather excessive, and we're wondering if one can improve the stored procedures or skip it and call Cosmos db directly.

{
  "id": "b780de47-a7d2-44c5-8a8f-7eea29e9561f__GrainReference=4f3d549833293c5e5d419486ec1f04a30600000031c1478e+7054fbd0-9dce-48ed-ab5c-4ed85ba0c66c",
  "GrainType": "Ps.Personlig.Grains.FavorittGrainRadio",
  "State": {
    "State": {
      "Case": "V1",
      "Fields": [
        {
          "FavoriserbarId": "K|saann_er_du",
          "Medium": "radio",
          "KildeType": "manuell",
          "Registrert": 15481904238110000,
          "Slettet": {
            "Case": "Some",
            "Fields": [
              15518746264096320
            ]
          }
        }
      ]
    }
  },
  "PartitionKey": "testh"
}

FYI - working on a pr to call CosmosDB directly without stored procedures.

@Ulriksen the reason for the use of procedures, is the fact that we need atomic transactions.

There is no way to do that from the C# SDK...

Which part of the write needs an atomic transaction? The etag check can be done from the storage provider.

IIRC, it is the membership.

Sorry for not being precise, this is for persistence.

Ahhh ok.

Well, if you can do conditional writes on the C# client, I'm fine with it, go ahead.