Den här artikeln beskriver hur du aktiverar autoskalning av genomströmning för 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 autoskalningsdataflöde i en databas och dela det mellan alla containrar i databasen.
Om du använder ett annat API kan du läsa API för MongoDB, API för Cassandra eller API för Gremlin.
Azure Portal
Skapa ny databas eller container med autoskalning
Logga in på Azure-portalen eller Azure Cosmos DB-utforskaren.
Gå till ditt Azure Cosmos DB-konto och öppna fliken Datautforskaren .
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öde (RU/s) som du vill att databasen eller containern ska skalas till.
Välj OK.
Om du vill etablera autoskalning på databasen för delat dataflöde väljer du alternativet Etablera databasdataflöde när du skapar en ny databas.
Anteckning
Att ange dataflöde på databasnivå rekommenderas endast för utveckling/test eller när arbetsbelastningen i alla containrar i databasen för delat dataflöde är enhetlig. För bästa prestanda för stora produktionsarbetsbelastningar rekommenderar vi att du anger dedikerat dataflöde (autoskalning eller manuell) på containernivå och inte på databasnivå.
Aktivera autoskalning för befintlig databas eller container
Logga in på Azure-portalen eller Azure Cosmos DB-utforskaren.
Gå till ditt Azure Cosmos DB-konto och öppna fliken Datautforskaren .
Välj Skala och inställningar för containern eller Skala för databasen.
Under Skala väljer du alternativet Autoskalning och Spara.
Anteckning
När du aktiverar autoskalning i 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 maximalt antal RU/s om det behövs. Mer information finns i Vanliga frågor och svar om autoskalning med tilldelad dataflödeskapacitet.
SDKs
Använd följande SDK:er för att hantera resurser för automatisk skalning:
Skapa databas med delat dataflöde
Anteckning
Att ange dataflöde på databasnivå rekommenderas endast för utveckling/test eller när arbetsbelastningen i alla containrar i databasen för delat dataflöde är enhetlig. För bästa prestanda för stora produktionsarbetsbelastningar rekommenderar vi att du anger dedikerat dataflöde (autoskalning eller manuell) på containernivå och inte på databasnivå.
Använd version 3.9 eller senare av Azure Cosmos DB .NET SDK för API för NoSQL för att hantera autoskalningsresurser.
Viktigt!
Du kan använda .NET SDK för att skapa nya autoskalningsresurser. SDK stöder inte migrering mellan autoskalning och standard (manuell) genomströmning. Migreringsscenariot stöds för närvarande endast i Azure Portal, CLI och PowerShell.
Anteckning
När du aktiverar autoskalning i 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 maximalt antal RU/s om det behövs. Mer information finns i Vanliga frågor och svar om autoskalning med tilldelad dataflödeskapacitet.
// 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);
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 autoskalningsresurser.
Viktigt!
Du kan använda Java SDK för att skapa nya autoskalningsresurser. SDK stöder inte migrering mellan autoskalning och standard (manuell) genomströmning. Migreringsscenariot stöds för närvarande endast i Azure Portal, CLI och PowerShell.
Anteckning
När du aktiverar autoskalning i 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 maximalt antal RU/s om det behövs. Mer information finns i Vanliga frågor och svar om autoskalning med tilldelad dataflödeskapacitet.
Asynkrona
// 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();
Synkronisering
// Create instance of CosmosClient
CosmosClient client = new CosmosClientBuilder()
.setEndpoint(HOST)
.setKey(PRIMARYKEY)
.setConnectionPolicy(CONNECTIONPOLICY)
.buildClient();
// Autoscale throughput settings
ThroughputProperties autoscaleThroughputProperties = ThroughputProperties.createAutoscaledThroughput(1000); //Set autoscale max RU/s
//Create the database with autoscale enabled
CosmosDatabase database = client.createDatabase(databaseName, autoscaleThroughputProperties).getDatabase();
Viktigt!
Du kan använda Python SDK för att skapa nya autoskalningsresurser. SDK stöder inte migrering mellan autoskalning och standard (manuell) genomströmning. Migreringsscenariot stöds för närvarande endast i Azure Portal, CLI och PowerShell.
Anteckning
När du aktiverar autoskalning i 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 maximalt antal RU/s om det behövs. Mer information finns i Vanliga frågor och svar om autoskalning med tilldelad dataflödeskapacitet.
Synkronisering
from azure.cosmos import CosmosClient, ThroughputProperties
# Create your CosmosClient instance
client = CosmosClient(host, credential)
# Autoscale throughput settings
throughput_properties = ThroughputProperties(auto_scale_max_throughput=5000) #Set autoscale max RU/s
#Create the database with autoscale enabled
client.create_database(id=database_id, offer_throughput=throughput_properties)
Asynkrona
from azure.cosmos import ThroughputProperties
from azure.cosmos.aio import CosmosClient
# Create your CosmosClient instance
async with CosmosClient(host, credential) as client:
# Autoscale throughput settings
throughput_properties = ThroughputProperties(auto_scale_max_throughput=5000) #Set autoscale max RU/s
#Create the database with autoscale enabled
await client.create_database(id=database_id, offer_throughput=throughput_properties)
Du kan använda DataflödeEgenskaper för databas- och containerresurser.
Viktigt!
Du kan använda Go SDK för att skapa nya autoskalningsresurser. SDK stöder inte migrering mellan autoskalning och standard (manuell) genomströmning. Migreringsscenariot stöds för närvarande endast i Azure Portal, CLI och PowerShell.
Anteckning
När du aktiverar autoskalning i 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 maximalt antal RU/s om det behövs. Mer information finns i Vanliga frågor och svar om autoskalning med tilldelad dataflödeskapacitet.
// autoscale throughput properties
db_throughput := azcosmos.NewAutoscaleThroughputProperties(4000)
_, err = client.CreateDatabase(context.Background(), azcosmos.DatabaseProperties{
ID: "demo_db",
}, &azcosmos.CreateDatabaseOptions{
ThroughputProperties: &db_throughput,
})
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);
Asynkrona
// 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();
Synkronisering
// Get reference to database that container will be created in
CosmosDatabase database = client.createDatabase("DatabaseName").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
CosmosContainer container = database.createContainer(autoscaleContainerProperties, autoscaleThroughputProperties, new CosmosContainerRequestOptions())
.getContainer();
Synkronisering
from azure.cosmos import CosmosClient, ThroughputProperties
# Create your CosmosClient instance
client = CosmosClient(host, credential)
# Get your DatabaseProxy object
database = client.get_database_client(database_id)
# Autoscale throughput settings
throughput_properties = ThroughputProperties(auto_scale_max_throughput=5000) #Set autoscale max RU/s
#Create the container with autoscale enabled
database.create_container(id=container_id, partition_key=partition_key, offer_throughput=throughput_properties)
Asynkrona
from azure.cosmos import ThroughputProperties
from azure.cosmos.aio import CosmosClient
# Create your CosmosClient instance
async with CosmosClient(host, credential) as client:
# Get your DatabaseProxy object
database = client.get_database_client(database_id)
# Autoscale throughput settings
throughput_properties = ThroughputProperties(auto_scale_max_throughput=5000) #Set autoscale max RU/s
#Create the container with autoscale enabled
await database.create_container(id=container_id, partition_key=partition_key, offer_throughput=throughput_properties)
pkDefinition := azcosmos.PartitionKeyDefinition{
Paths: []string{"/state"},
Kind: azcosmos.PartitionKeyKindHash,
}
// autoscale throughput properties
throughput := azcosmos.NewAutoscaleThroughputProperties(4000)
db.CreateContainer(context.Background(), azcosmos.ContainerProperties{
ID: "demo_container",
PartitionKeyDefinition: pkDefinition,
}, &azcosmos.CreateContainerOptions{
ThroughputProperties: &throughput,
})
Läs den aktuella genomströmningen (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;
Asynkrona
// 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;
Synkronisering
// Get a reference to the resource
CosmosContainer container = client.getDatabase("DatabaseName").getContainer("ContainerName");
// Read the throughput on a resource
ThroughputProperties autoscaleContainerThroughput = container.readThroughput().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;
Synkronisering
from azure.cosmos import CosmosClient, ThroughputProperties
# Create your CosmosClient instance
client = CosmosClient(host, credential)
# Get your DatabaseProxy object
database = client.get_database_client(database_id)
# Get your ContainerProxy object
container = database.get_container_client(container_id)
# Get your throughput settings
throughput = container.get_throughput()
# Get the autoscale max throughput (RU/s) of the resource
auto_scale_throughput = throughput.auto_scale_max_throughput
# Get the throughput (RU/s) the resource is currently scaled to
current_throughput = throughput.offer_throughput
Asynkrona
from azure.cosmos import ThroughputProperties
from azure.cosmos.aio import CosmosClient
# Create your CosmosClient instance
async with CosmosClient(host, credential) as client:
# Get your DatabaseProxy object
database = client.get_database_client(database_id)
# Get your ContainerProxy object
container = database.get_container_client(container_id)
# Get your throughput settings
throughput = await container.get_throughput()
# Get the autoscale max throughput (RU/s) of the resource
auto_scale_throughput = throughput.auto_scale_max_throughput
# Get the throughput (RU/s) the resource is currently scaled to
current_throughput = throughput.offer_throughput
Ändra maximalt dataflöde för autoskalning (RU/s)
// Change the autoscale max throughput (RU/s)
await container.ReplaceThroughputAsync(ThroughputProperties.CreateAutoscaleThroughput(newAutoscaleMaxThroughput));
Asynkrona
// Change the autoscale max throughput (RU/s)
container.replaceThroughput(ThroughputProperties.createAutoscaledThroughput(newAutoscaleMaxThroughput)).block();
Synkronisering
// Change the autoscale max throughput (RU/s)
container.replaceThroughput(ThroughputProperties.createAutoscaledThroughput(newAutoscaleMaxThroughput));
Synkronisering
from azure.cosmos import ThroughputProperties
# Change the autoscale max throughput (RU/s)
container.replace_throughput(ThroughputProperties(auto_scale_max_throughput=8000))
Asynkrona
from azure.cosmos import ThroughputProperties
# Change the autoscale max throughput (RU/s)
await container.replace_throughput(ThroughputProperties(auto_scale_max_throughput=8000))
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. Exempel finns i Azure Resource Manager-mallar för Azure Cosmos DB.
Det går inte att använda Azure Resource Manager-mallar för att migrera mellan förutbestämt dataflöde och autoskalningsflöde på en befintlig resurs.
Azure CLI
Azure CLI kan användas för att etablera autoskalningsdataflöde på en ny databas eller resurs på containernivå för alla Azure Cosmos DB-API:er eller för att aktivera autoskalning på en befintlig resurs.
Azure PowerShell
Azure PowerShell kan användas för att etablera autoskalningsdataflöde på en ny databas eller resurs på containernivå för alla Azure Cosmos DB-API:er eller för att aktivera autoskalning på en befintlig resurs.
Nästa steg