Doorvoer voor automatische schaalaanpassing inrichten voor database of container in Azure Cosmos DB - API voor NoSQL

VAN TOEPASSING OP: NoSQL

In dit artikel wordt uitgelegd hoe u doorvoer voor automatische schaalaanpassing kunt inrichten voor een database of container (verzameling, grafiek of tabel) in Azure Cosmos DB voor NoSQL. U kunt automatische schaalaanpassing voor één container inschakelen of doorvoer voor automatische schaalaanpassing voor een database inrichten en deze delen tussen alle containers in de database.

Als u een andere API gebruikt, raadpleegt u de artikelen API voor MongoDB, API voor Cassandra en API voor Gremlin om de doorvoer in te richten.

Azure Portal

Nieuwe database of container maken met automatische schaalaanpassing

  1. Meld u aan bij de Azure Portal of de Verkenner van Azure Cosmos DB.

  2. Navigeer naar uw Azure Cosmos DB-account en open het tabblad Data Explorer.

  3. Selecteer Nieuwe container. Voer een naam in voor uw database, container en een partitiesleutel. Selecteer onder database- of containerdoorvoer de optie Automatische schaalaanpassing en stel de maximale doorvoer (RU/s) in waarnaar u de database of container wilt schalen.

    Een container maken en ingerichte doorvoer voor automatisch schalen configureren

  4. Selecteer OK.

Als u automatische schaalaanpassing wilt inrichten voor een gedeelde doorvoerdatabase, selecteert u de optie Databasedoorvoer inrichten bij het maken van een nieuwe database.

Automatische schaalaanpassing inschakelen voor een bestaande database of container

  1. Meld u aan bij de Azure Portal of de Verkenner van Azure Cosmos DB.

  2. Navigeer naar uw Azure Cosmos DB-account en open het tabblad Data Explorer.

  3. Selecteer Schalen en instellingen voor uw container of Schaal voor uw database.

  4. Selecteer onder Schalen de optie Automatisch schalen en Selecteer Opslaan.

    Automatische schaalaanpassing inschakelen voor een bestaande container

Notitie

Wanneer u automatische schaalaanpassing inschakelt voor een bestaande database of container, wordt de beginwaarde voor het maximum aantal RU/s bepaald door het systeem, op basis van uw huidige handmatig ingerichte doorvoerinstellingen en opslag. Nadat de bewerking is voltooid, kunt u indien nodig het maximum aantal RU/s wijzigen. Meer informatie.

Azure Cosmos DB .NET V3 SDK

Gebruik versie 3.9 of hoger van de Azure Cosmos DB .NET SDK voor API for NoSQL om resources automatisch te schalen.

Belangrijk

U kunt de .NET SDK gebruiken om nieuwe resources voor automatische schaalaanpassing te maken. De SDK biedt geen ondersteuning voor migratie tussen automatische schaalaanpassing en standaard (handmatige) doorvoer. Het migratiescenario wordt momenteel alleen ondersteund in de Azure Portal, CLI en PowerShell.

Database maken met gedeelde doorvoer

// Create instance of CosmosClient
CosmosClient cosmosClient = new CosmosClient(Endpoint, PrimaryKey);
 
// Autoscale throughput settings
ThroughputProperties autoscaleThroughputProperties = ThroughputProperties.CreateAutoscaleThroughput(1000); //Set autoscale max RU/s

//Create the database with autoscale enabled
database = await cosmosClient.CreateDatabaseAsync(DatabaseName, throughputProperties: autoscaleThroughputProperties);

Container met toegewezen doorvoer maken

// Get reference to database that container will be created in
Database database = await cosmosClient.GetDatabase("DatabaseName");

// Container and autoscale throughput settings
ContainerProperties autoscaleContainerProperties = new ContainerProperties("ContainerName", "/partitionKey");
ThroughputProperties autoscaleThroughputProperties = ThroughputProperties.CreateAutoscaleThroughput(1000); //Set autoscale max RU/s

// Create the container with autoscale enabled
container = await database.CreateContainerAsync(autoscaleContainerProperties, autoscaleThroughputProperties);

De huidige doorvoer (RU/s) lezen

// Get a reference to the resource
Container container = cosmosClient.GetDatabase("DatabaseName").GetContainer("ContainerName");

// Read the throughput on a resource
ThroughputProperties autoscaleContainerThroughput = await container.ReadThroughputAsync(requestOptions: null); 

// The autoscale max throughput (RU/s) of the resource
int? autoscaleMaxThroughput = autoscaleContainerThroughput.AutoscaleMaxThroughput;

// The throughput (RU/s) the resource is currently scaled to
int? currentThroughput = autoscaleContainerThroughput.Throughput;

De maximale doorvoer voor automatisch schalen (RU/s) wijzigen

// Change the autoscale max throughput (RU/s)
await container.ReplaceThroughputAsync(ThroughputProperties.CreateAutoscaleThroughput(newAutoscaleMaxThroughput));

Azure Cosmos DB Java V4 SDK

U kunt versie 4.0 of hoger van de Azure Cosmos DB Java SDK voor API for NoSQL gebruiken om resources automatisch te schalen.

Belangrijk

U kunt de Java SDK gebruiken om nieuwe resources voor automatisch schalen te maken. De SDK biedt geen ondersteuning voor migratie tussen automatische schaalaanpassing en standaard (handmatige) doorvoer. Het migratiescenario wordt momenteel alleen ondersteund in de Azure Portal, CLI en PowerShell.

Database maken met gedeelde doorvoer

// Create instance of CosmosClient
CosmosAsyncClient client = new CosmosClientBuilder()
    .setEndpoint(HOST)
    .setKey(PRIMARYKEY)
    .setConnectionPolicy(CONNECTIONPOLICY)
    .buildAsyncClient();

// Autoscale throughput settings
ThroughputProperties autoscaleThroughputProperties = ThroughputProperties.createAutoscaledThroughput(1000); //Set autoscale max RU/s

//Create the database with autoscale enabled
CosmosAsyncDatabase database = client.createDatabase(databaseName, autoscaleThroughputProperties).block().getDatabase();

Container met toegewezen doorvoer maken

// Get reference to database that container will be created in
CosmosAsyncDatabase database = client.createDatabase("DatabaseName").block().getDatabase();

// Container and autoscale throughput settings
CosmosContainerProperties autoscaleContainerProperties = new CosmosContainerProperties("ContainerName", "/partitionKey");
ThroughputProperties autoscaleThroughputProperties = ThroughputProperties.createAutoscaledThroughput(1000); //Set autoscale max RU/s

// Create the container with autoscale enabled
CosmosAsyncContainer container = database.createContainer(autoscaleContainerProperties, autoscaleThroughputProperties, new CosmosContainerRequestOptions())
                                .block()
                                .getContainer();

De huidige doorvoer (RU/s) lezen

// Get a reference to the resource
CosmosAsyncContainer container = client.getDatabase("DatabaseName").getContainer("ContainerName");

// Read the throughput on a resource
ThroughputProperties autoscaleContainerThroughput = container.readThroughput().block().getProperties();

// The autoscale max throughput (RU/s) of the resource
int autoscaleMaxThroughput = autoscaleContainerThroughput.getAutoscaleMaxThroughput();

// The throughput (RU/s) the resource is currently scaled to
int currentThroughput = autoscaleContainerThroughput.Throughput;

De maximale doorvoer voor automatisch schalen (RU/s) wijzigen

// Change the autoscale max throughput (RU/s)
container.replaceThroughput(ThroughputProperties.createAutoscaledThroughput(newAutoscaleMaxThroughput)).block();

Azure Resource Manager

Azure Resource Manager-sjablonen kunnen worden gebruikt voor het inrichten van doorvoer voor automatische schaalaanpassing voor een nieuwe database of resource op containerniveau voor alle Azure Cosmos DB-API's. Zie Azure Resource Manager-sjablonen voor Azure Cosmos DB voor voorbeelden. Standaard kunnen Azure Resource Manager-sjablonen niet worden gebruikt om te migreren tussen ingerichte doorvoer en automatische schaalaanpassing voor een bestaande resource.

Azure CLI

Azure CLI kan worden gebruikt om doorvoer voor automatische schaalaanpassing in te richten op een nieuwe database of resource op containerniveau voor alle Azure Cosmos DB-API's, of om automatische schaalaanpassing in te schakelen voor een bestaande resource. Zie Azure CLI-voorbeelden voor Azure Cosmos DB voor voorbeelden.

Azure PowerShell

Azure PowerShell kunt u gebruiken om doorvoer voor automatische schaalaanpassing in te richten voor een nieuwe database of resource op containerniveau voor alle Azure Cosmos DB-API's, of om automatische schaalaanpassing in te schakelen voor een bestaande resource. Zie Azure PowerShell voorbeelden voor Azure Cosmos DB voor voorbeelden.

Volgende stappen