Skip to content

Instantly share code, notes, and snippets.

@deborahc
Last active August 1, 2019 00:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deborahc/499ff7c21382dd55969277f667323bb7 to your computer and use it in GitHub Desktop.
Save deborahc/499ff7c21382dd55969277f667323bb7 to your computer and use it in GitHub Desktop.
Scale throughput of a container in Azure Cosmos DB .NET SDK V3 (GA)
// Scaling throughput (RU/s) using V3 SDK
static async Task ScaleThroughputDemo_SDKVersion3()
{
// Get reference to container
var container = cosmosClient.GetContainer(databaseId, containerId);
// Read value of current throughput (RU/s)
var currentThroughput = await container.ReadThroughputAsync();
var newThroughput = (int)currentThroughput * 2;
// Replace throughput with new value
var throughputResponse = await container.ReplaceThroughputAsync(newThroughput);
}
// For comparison, using V2 SDK
static async Task ScaleThroughputDemo_SDKVersion2()
{
var client = new DocumentClient(new Uri(endpointUrl), authorizationKey);
// Read value of current throughput (RU/s)
Offer offer = client.CreateOfferQuery().Where(o => o.ResourceLink == collection.SelfLink).AsEnumerable().Single();
// Replace throughput with new value
Offer replaced = await client.ReplaceOfferAsync(new OfferV2(offer, 500));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment