Tento článek vysvětluje, jak povolit propustnost automatického škálování v databázi nebo kontejneru (kolekci, grafu nebo tabulce) ve službě Azure Cosmos DB for NoSQL. Automatické škálování můžete povolit v jednom kontejneru nebo zřídit propustnost automatického škálování v databázi a sdílet ji mezi všemi kontejnery v databázi.
Pokud používáte jiné rozhraní API, přečtěte si téma Rozhraní API pro MongoDB, rozhraní API pro Cassandra nebo rozhraní API pro Gremlin.
Azure Portal
Vytvoření nové databáze nebo kontejneru s automatickým škálováním
Přihlaste se k webu Azure Portal nebo průzkumníku služby Azure Cosmos DB.
Přejděte do svého účtu služby Azure Cosmos DB a otevřete záložku Průzkumník dat.
Vyberte Nový kontejner. Zadejte název databáze, kontejneru a klíče oddílu.
V části Databáze nebo propustnost kontejneru vyberte možnost Automatické škálování a nastavte maximální propustnost (RU/s), na kterou chcete databázi nebo kontejner škálovat.
Vyberte OK.
Pokud chcete zřídit automatické škálování pro databázi se sdílenou propustností, vyberte při vytváření nové databáze možnost Zřídit propustnost databáze.
Note
Nastavení propustnosti na úrovni databáze se doporučuje jenom pro vývoj/testování nebo v případě, že je jednotná úloha napříč všemi kontejnery v databázi se sdílenou propustností. Pro zajištění nejlepšího výkonu pro velké produkční úlohy se doporučuje nastavit vyhrazenou propustnost (automatické škálování nebo ruční) na úrovni kontejneru, nikoli na úrovni databáze.
Povolení automatického škálování u existující databáze nebo kontejneru
Přihlaste se k webu Azure Portal nebo průzkumníku služby Azure Cosmos DB.
Přejděte do svého účtu služby Azure Cosmos DB a otevřete záložku Průzkumník dat.
Vyberte Škálování a Nastavení pro váš kontejner, nebo Škálování pro vaši databázi.
V části Měřítko vyberte možnost Automatické škálování a Uložte.
Note
Když u existující databáze nebo kontejneru povolíte automatické škálování, určuje systém počáteční hodnotu maximálního počtu RU/s na základě aktuálního nastavení ručně zřízené propustnosti a úložiště. Po dokončení operace můžete v případě potřeby změnit maximální počet RU/s. Další informace najdete v tématu Nejčastější dotazy týkající se automaticky škálované zřízené propustnosti.
SDKs
Ke správě prostředků automatického škálování použijte následující sady SDK:
Vytvoření databáze se sdílenou propustností
Note
Nastavení propustnosti na úrovni databáze se doporučuje jenom pro vývoj/testování nebo v případě, že je jednotná úloha napříč všemi kontejnery v databázi se sdílenou propustností. Pro zajištění nejlepšího výkonu pro velké produkční úlohy se doporučuje nastavit vyhrazenou propustnost (automatické škálování nebo ruční) na úrovni kontejneru, nikoli na úrovni databáze.
Ke správě prostředků automatického škálování použijte verzi 3.9 nebo vyšší sady .NET SDK služby Azure Cosmos DB pro rozhraní API for NoSQL.
Important
Sadu .NET SDK můžete použít k vytvoření nových prostředků automatického škálování. Sada SDK nepodporuje migraci mezi automatickou a standardní (ruční) propustností. Scénář migrace se v současné době podporuje jenom na webu Azure Portal, rozhraní příkazového řádku a PowerShellu.
Note
Když u existující databáze nebo kontejneru povolíte automatické škálování, určuje systém počáteční hodnotu maximálního počtu RU/s na základě aktuálního nastavení ručně zřízené propustnosti a úložiště. Po dokončení operace můžete v případě potřeby změnit maximální počet RU/s. Další informace najdete v tématu Nejčastější dotazy týkající se automaticky škálované zřízené propustnosti.
// 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);
Ke správě prostředků automatického škálování můžete použít verzi 4.0 nebo vyšší sady Java SDK služby Azure Cosmos DB pro rozhraní API for NoSQL.
Important
Sadu Java SDK můžete použít k vytvoření nových prostředků automatického škálování. Sada SDK nepodporuje migraci mezi automatickou a standardní (ruční) propustností. Scénář migrace se v současné době podporuje jenom na webu Azure Portal, rozhraní příkazového řádku a PowerShellu.
Note
Když u existující databáze nebo kontejneru povolíte automatické škálování, určuje systém počáteční hodnotu maximálního počtu RU/s na základě aktuálního nastavení ručně zřízené propustnosti a úložiště. Po dokončení operace můžete v případě potřeby změnit maximální počet RU/s. Další informace najdete v tématu Nejčastější dotazy týkající se automaticky škálované zřízené propustnosti.
Async
// 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();
Synchronizovat
// 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();
Important
Sadu Python SDK můžete použít k vytvoření nových prostředků automatického škálování. Sada SDK nepodporuje migraci mezi automatickou a standardní (ruční) propustností. Scénář migrace se v současné době podporuje jenom na webu Azure Portal, rozhraní příkazového řádku a PowerShellu.
Note
Když u existující databáze nebo kontejneru povolíte automatické škálování, určuje systém počáteční hodnotu maximálního počtu RU/s na základě aktuálního nastavení ručně zřízené propustnosti a úložiště. Po dokončení operace můžete v případě potřeby změnit maximální počet RU/s. Další informace najdete v tématu Nejčastější dotazy týkající se automaticky škálované zřízené propustnosti.
Synchronizovat
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)
Async
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)
ThroughputProperties můžete použít na prostředky databáze a kontejneru.
Important
Sadu Go SDK můžete použít k vytvoření nových prostředků automatického škálování. Sada SDK nepodporuje migraci mezi automatickou a standardní (ruční) propustností. Scénář migrace se v současné době podporuje jenom na webu Azure Portal, rozhraní příkazového řádku a PowerShellu.
Note
Když u existující databáze nebo kontejneru povolíte automatické škálování, určuje systém počáteční hodnotu maximálního počtu RU/s na základě aktuálního nastavení ručně zřízené propustnosti a úložiště. Po dokončení operace můžete v případě potřeby změnit maximální počet RU/s. Další informace najdete v tématu Nejčastější dotazy týkající se automaticky škálované zřízené propustnosti.
// autoscale throughput properties
db_throughput := azcosmos.NewAutoscaleThroughputProperties(4000)
_, err = client.CreateDatabase(context.Background(), azcosmos.DatabaseProperties{
ID: "demo_db",
}, &azcosmos.CreateDatabaseOptions{
ThroughputProperties: &db_throughput,
})
Vytvoření kontejneru s vyhrazenou propustností
// 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);
Async
// 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();
Synchronizovat
// 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();
Synchronizovat
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)
Async
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,
})
Čtení aktuální propustnosti (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;
Async
// 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;
Synchronizovat
// 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;
Synchronizovat
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
Async
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
Nastavení maximální kapacity automatického škálování (RU/s)
// Change the autoscale max throughput (RU/s)
await container.ReplaceThroughputAsync(ThroughputProperties.CreateAutoscaleThroughput(newAutoscaleMaxThroughput));
Async
// Change the autoscale max throughput (RU/s)
container.replaceThroughput(ThroughputProperties.createAutoscaledThroughput(newAutoscaleMaxThroughput)).block();
Synchronizovat
// Change the autoscale max throughput (RU/s)
container.replaceThroughput(ThroughputProperties.createAutoscaledThroughput(newAutoscaleMaxThroughput));
Synchronizovat
from azure.cosmos import ThroughputProperties
# Change the autoscale max throughput (RU/s)
container.replace_throughput(ThroughputProperties(auto_scale_max_throughput=8000))
Async
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
Šablony Azure Resource Manageru je možné použít ke zřízení automatické škálovatelné propustnosti pro nový databázový nebo kontejnerový prostředek u všech rozhraní API služby Azure Cosmos DB. Ukázky najdete v šablonách Azure Resource Manageru pro službu Azure Cosmos DB.
Šablony Azure Resource Manageru se záměrně nedají použít k migraci mezi zřízenou propustností a propustností automatického škálování u existujícího prostředku.
Azure CLI
Azure CLI se dá použít ke zřízení propustnosti automatického škálování pro nový prostředek databáze nebo kontejneru pro všechna rozhraní API služby Azure Cosmos DB nebo k povolení automatického škálování u existujícího prostředku.
Azure PowerShell
Azure PowerShell se dá použít ke zřízení propustnosti automatického škálování pro nový prostředek databáze nebo kontejneru pro všechna rozhraní API služby Azure Cosmos DB nebo k povolení automatického škálování u existujícího prostředku.
Další kroky