Cosmos DB Throttled Requests

Tahmid Eshayat 286 Reputation points
2020-06-03T06:38:50.127+00:00

Hi there,

I have a few thousands request every 30 secs. I have autopilot mode on with 4000 RU/s.
But I can see I'm getting lot of throttling requests. I'm currently storing all the insert functions into a task and
then using Task.WhenAll.

// Cosmos Tasks Execution  
await Task.WhenAll(concurrentTasks);  

8946-screenshot-1.jpg

The bulk insert would have been a batter choice for me, but I couldn't find any.
Is there any way where I can wait a couple of seconds so that I don't get 429 errors.

I have added a custom throttling function in the builder but seems to be not working.

configurationBuilder.AddCustomHandlers(new ThrottlingHandler());  

Help would be appreciated. Thanks

Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,680 questions
{count} votes

Accepted answer
  1. Mark Brown - MSFT 2,766 Reputation points Microsoft Employee
    2020-06-03T14:04:12.147+00:00

    If the instance of your Cosmos client only does these bulk inserts then create your client using the AllowBulkExecution setting below.

    new CosmosClient(endpoint, authKey, new CosmosClientOptions() { AllowBulkExecution = true});
    

    Would be helpful to see the code for your custom handler to better understand why that is not working. But generally speaking you should trap for 429 responses and implement a backoff/retry policy with Polly with a one second interval. However, with bulk mode enabled you should see far fewer of these anyway.

    Thanks.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.