Etablera dataflöde för automatisk skalning på databas eller container i Azure Cosmos DB – API för NoSQL

GÄLLER FÖR: NoSQL

Den här artikeln beskriver hur du etablerar dataflöde för automatisk skalning på en databas eller container (samling, graf eller tabell) i Azure Cosmos DB för NoSQL. Du kan aktivera autoskalning på en enda container eller etablera dataflöde för automatisk skalning i en databas och dela det mellan alla containrar i databasen.

Om du använder ett annat API kan du läsa artikeln API for MongoDB, API for Cassandra, API for Gremlin för att etablera dataflödet.

Azure Portal

Skapa ny databas eller container med autoskalning

  1. Logga in på Azure Portal eller Azure Cosmos DB-utforskaren.

  2. Gå till ditt Azure Cosmos DB-konto och öppna fliken Data Explorer.

  3. Välj Ny container. Ange ett namn för databasen, containern och en partitionsnyckel. Under databas- eller containerdataflöde väljer du alternativet Autoskalning och anger det maximala dataflödet (RU/s) som du vill att databasen eller containern ska skalas till.

    Skapa en container och konfigurera automatiskt etablerat dataflöde

  4. Välj OK.

Om du vill etablera autoskalning för databasen för delat dataflöde väljer du alternativet Etablera databasdataflöde när du skapar en ny databas.

Aktivera autoskalning på befintlig databas eller container

  1. Logga in på Azure Portal eller Azure Cosmos DB-utforskaren.

  2. Gå till ditt Azure Cosmos DB-konto och öppna fliken Data Explorer.

  3. Välj Skala och inställningar för containern eller Skala för databasen.

  4. Under Skala väljer du alternativet Autoskalning och Spara.

    Aktivera autoskalning på en befintlig container

Anteckning

När du aktiverar autoskalning på en befintlig databas eller container bestäms startvärdet för max RU/s av systemet baserat på dina aktuella manuella etablerade dataflödesinställningar och lagring. När åtgärden är klar kan du ändra max antal RU/s om det behövs. Läs mer.

Azure Cosmos DB .NET V3 SDK

Använd version 3.9 eller senare av Azure Cosmos DB .NET SDK för API för NoSQL för att hantera resurser för automatisk skalning.

Viktigt

Du kan använda .NET SDK för att skapa nya autoskalningsresurser. SDK stöder inte migrering mellan autoskalning och standarddataflöde (manuell). Migreringsscenariot stöds för närvarande endast i Azure Portal, CLI och PowerShell.

Skapa en databas med delat dataflöde

// 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);

Skapa container med dedikerat dataflöde

// 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);

Läs det aktuella dataflödet (RU/s)

// 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;

Ändra maximalt dataflöde för automatisk skalning (RU/s)

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

Azure Cosmos DB Java V4 SDK

Du kan använda version 4.0 eller senare av Azure Cosmos DB Java SDK för API för NoSQL för att hantera resurser för automatisk skalning.

Viktigt

Du kan använda Java SDK för att skapa nya autoskalningsresurser. SDK stöder inte migrering mellan autoskalning och standarddataflöde (manuell). Migreringsscenariot stöds för närvarande endast i Azure Portal, CLI och PowerShell.

Skapa en databas med delat dataflöde

// 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();

Skapa container med dedikerat dataflöde

// 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();

Läs det aktuella dataflödet (RU/s)

// 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;

Ändra maximalt dataflöde för automatisk skalning (RU/s)

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

Azure Resource Manager

Azure Resource Manager-mallar kan användas för att etablera dataflöde för automatisk skalning på en ny databas eller resurs på containernivå för alla Azure Cosmos DB-API:er. Se Azure Resource Manager-mallar för Azure Cosmos DB för exempel. Det går inte att använda Azure Resource Manager-mallar för att migrera mellan etablerat dataflöde och autoskalning för en befintlig resurs.

Azure CLI

Azure CLI kan användas för att etablera dataflöde för automatisk skalning på en ny databas eller resurs på containernivå för alla Azure Cosmos DB-API:er eller aktivera automatisk skalning för en befintlig resurs. Exempel finns i Azure CLI-exempel för Azure Cosmos DB.

Azure PowerShell

Azure PowerShell kan användas för att etablera dataflöde för automatisk skalning på en ny databas eller resurs på containernivå för alla Azure Cosmos DB-API:er eller aktivera automatisk skalning för en befintlig resurs. Exempel finns i Azure PowerShell exempel för Azure Cosmos DB.

Nästa steg