Handling Request Units per Second (RUs/s) Spikes in DocumentDB

霸气de小男生 提交于 2019-12-12 12:22:17

问题


One of the most difficult things with DocumentDB is figuring out how many Request Units per Second (RUs/s) you need to run your application day to day but also during usage spikes. When you get this wrong, the DocumentDB client will throw exceptions, which is a terrible usage model.

If my application has particular times of the day where it would use a higher number of Request Units per Second (RUs/s), then how do I handle this in DocumentDB? I don't want to set a really high RUs/s all day because I would get charged accordingly. I also don't want to have to log into the Azure portal each time.


回答1:


You could create a job on Azure that scales up the throughput of your collections only at the time of day that you need it and then scale down afterward.

If you are targeting DocumentDB from .NET, this Azure article has example code that shows how to change the throughput using the .NET SDK.

The specific (C# .NET) code referenced in the article looks like this:

//Fetch the resource to be updated
Offer offer = client.CreateOfferQuery()
              .Where(r => r.ResourceLink == collection.SelfLink)    
              .AsEnumerable()
              .SingleOrDefault();

// Set the throughput to 5000 request units per second
offer = new OfferV2(offer, 5000);

//Now persist these changes to the database by replacing the original resource
await client.ReplaceOfferAsync(offer);

// Set the throughput to S2
offer = new Offer(offer);
offer.OfferType = "S2";

//Now persist these changes to the database by replacing the original resource
await client.ReplaceOfferAsync(offer);

I assume that the DocumentDB SDK for other languages would have the same feature.

Additionally, from an Azure article found here you can use PowerShell to change the service level.

$ResourceGroupName = "resourceGroupName"

$ServerName = "serverName"
$DatabaseName = "databaseName"

$NewEdition = "Standard"
$NewPricingTier = "S2"

$ScaleRequest = Set-AzureRmSqlDatabase -DatabaseName $DatabaseName -   ServerName $ServerName -ResourceGroupName $ResourceGroupName -Edition     $NewEdition -RequestedServiceObjectiveName $NewPricingTier


来源:https://stackoverflow.com/questions/36714563/handling-request-units-per-second-rus-s-spikes-in-documentdb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!