Questo articolo illustra come abilitare la velocità effettiva di scalabilità automatica in un database o in un contenitore (raccolta, grafo o tabella) in Azure Cosmos DB for NoSQL. È possibile abilitare la scalabilità automatica per un singolo contenitore oppure effettuare il provisioning della velocità effettiva per la scalabilità automatica a livello di database e condividerla tra tutti i contenitori nel database.
Se si usa un'API diversa, vedere API per MongoDB, API per Cassandra o API per Gremlin.
Azure portal
Creare un nuovo database o contenitore con scalabilità automatica
Accedere al portale di Azure o ad Azure Cosmos DB Explorer.
Passare all'account Azure Cosmos DB e aprire la scheda Esplora dati.
Selezionare Nuovo contenitore. Immettere un nome per il database, il contenitore e una chiave di partizione.
Nella sezione della velocità effettiva del database o del container, selezionare l'opzione Scalabilità automatica e impostare la velocità effettiva massima (UR/s) per il dimensionamento del database o del contenitore.
Screenshot che illustra le impostazioni per creare un contenitore e configurare la produzione fornita con scalabilità automatica.
Seleziona OK.
Per effettuare il provisioning della scalabilità automatica per il database con velocità effettiva condivisa, selezionare l'opzione Provision database throughput (Effettua il provisioning della velocità effettiva del database) durante la creazione di un nuovo database.
Nota
L'impostazione della velocità effettiva a livello di database è consigliata solo per lo sviluppo/test o quando il carico di lavoro in tutti i contenitori nel database con velocità effettiva condivisa è uniforme. Per ottenere prestazioni ottimali per carichi di lavoro di produzione di grandi dimensioni, è consigliabile impostare velocità effettiva dedicata (scalabilità automatica o manuale) a livello di contenitore e non a livello di database.
Abilitare la scalabilità automatica per un database o un contenitore esistente
Accedere al portale di Azure o ad Azure Cosmos DB Explorer.
Passare all'account Azure Cosmos DB e aprire la scheda Esplora dati.
Selezionare Scalabilità e impostazioni per il contenitore oppure Dimensiona per il database.
In Dimensiona selezionare l'opzione Scalabilità automatica e fare clic su Salva.
Nota
Quando si abilita la scalabilità automatica per un database o un contenitore esistente, il valore iniziale per il numero massimo di UR/s è determinato dal sistema, in base alle impostazioni correnti del provisioning della velocità effettiva manuale e allo spazio di archiviazione. Al termine dell'operazione, se necessario, è possibile modificare il numero massimo di UR/s. Per altre informazioni, vedere Domande frequenti sulla velocità effettiva con provisioning con scalabilità automatica.
SDKs
Usare gli SDK seguenti per gestire le risorse di scalabilità automatica:
Creare un database con scalabilità condivisa
Nota
L'impostazione della velocità effettiva a livello di database è consigliata solo per lo sviluppo/test o quando il carico di lavoro in tutti i contenitori nel database con velocità effettiva condivisa è uniforme. Per ottenere prestazioni ottimali per carichi di lavoro di produzione di grandi dimensioni, è consigliabile impostare velocità effettiva dedicata (scalabilità automatica o manuale) a livello di contenitore e non a livello di database.
Usare la versione 3.9 o successiva di Azure Cosmos DB .NET SDK per API per NoSQL per gestire le risorse con scalabilità automatica.
Importante
È possibile usare .NET SDK per creare nuove risorse con scalabilità automatica. L'SDK non supporta la migrazione tra velocità effettiva di scalabilità automatica e velocità effettiva standard (manuale). Lo scenario di migrazione è attualmente supportato solo nel portale di Azure, nell'interfaccia della riga di comando di Azure e in PowerShell.
Nota
Quando si abilita la scalabilità automatica per un database o un contenitore esistente, il valore iniziale per il numero massimo di UR/s è determinato dal sistema, in base alle impostazioni correnti del provisioning della velocità effettiva manuale e allo spazio di archiviazione. Al termine dell'operazione, se necessario, è possibile modificare il numero massimo di UR/s. Per altre informazioni, vedere Domande frequenti sulla velocità effettiva con provisioning con scalabilità automatica.
// 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);
È possibile usare la versione 4.0 o successiva di Azure Cosmos DB Java SDK per API per NoSQL per gestire le risorse con scalabilità automatica.
Importante
È possibile usare Java SDK per creare nuove risorse con scalabilità automatica. L'SDK non supporta la migrazione tra velocità effettiva di scalabilità automatica e velocità effettiva standard (manuale). Lo scenario di migrazione è attualmente supportato solo nel portale di Azure, nell'interfaccia della riga di comando di Azure e in PowerShell.
Nota
Quando si abilita la scalabilità automatica per un database o un contenitore esistente, il valore iniziale per il numero massimo di UR/s è determinato dal sistema, in base alle impostazioni correnti del provisioning della velocità effettiva manuale e allo spazio di archiviazione. Al termine dell'operazione, se necessario, è possibile modificare il numero massimo di UR/s. Per altre informazioni, vedere Domande frequenti sulla velocità effettiva con provisioning con scalabilità automatica.
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();
Sincronizza
// 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();
Importante
È possibile usare Python SDK per creare nuove risorse di scalabilità automatica. L'SDK non supporta la migrazione tra velocità effettiva di scalabilità automatica e velocità effettiva standard (manuale). Lo scenario di migrazione è attualmente supportato solo nel portale di Azure, nell'interfaccia della riga di comando di Azure e in PowerShell.
Nota
Quando si abilita la scalabilità automatica per un database o un contenitore esistente, il valore iniziale per il numero massimo di UR/s è determinato dal sistema, in base alle impostazioni correnti del provisioning della velocità effettiva manuale e allo spazio di archiviazione. Al termine dell'operazione, se necessario, è possibile modificare il numero massimo di UR/s. Per altre informazioni, vedere Domande frequenti sulla velocità effettiva con provisioning con scalabilità automatica.
Sincronizza
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)
È possibile usare ThroughputProperties nelle risorse di database e contenitori.
Importante
È possibile usare Go SDK per creare nuove risorse di scalabilità automatica. L'SDK non supporta la migrazione tra velocità effettiva di scalabilità automatica e velocità effettiva standard (manuale). Lo scenario di migrazione è attualmente supportato solo nel portale di Azure, nell'interfaccia della riga di comando di Azure e in PowerShell.
Nota
Quando si abilita la scalabilità automatica per un database o un contenitore esistente, il valore iniziale per il numero massimo di UR/s è determinato dal sistema, in base alle impostazioni correnti del provisioning della velocità effettiva manuale e allo spazio di archiviazione. Al termine dell'operazione, se necessario, è possibile modificare il numero massimo di UR/s. Per altre informazioni, vedere Domande frequenti sulla velocità effettiva con provisioning con scalabilità automatica.
// autoscale throughput properties
db_throughput := azcosmos.NewAutoscaleThroughputProperties(4000)
_, err = client.CreateDatabase(context.Background(), azcosmos.DatabaseProperties{
ID: "demo_db",
}, &azcosmos.CreateDatabaseOptions{
ThroughputProperties: &db_throughput,
})
Creare il contenitore con velocità effettiva dedicata
// 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();
Sincronizza
// 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();
Sincronizza
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,
})
Leggere la velocità effettiva corrente (UR/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;
Sincronizza
// 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;
Sincronizza
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
Modificare la velocità effettiva massima per la scalabilità automatica (UR/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();
Sincronizza
// Change the autoscale max throughput (RU/s)
container.replaceThroughput(ThroughputProperties.createAutoscaledThroughput(newAutoscaleMaxThroughput));
Sincronizza
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
I modelli di Azure Resource Manager possono essere utilizzati per effettuare il provisioning del throughput a scalabilità automatica su una nuova risorsa a livello di database o a livello di contenitore per tutte le API di Azure Cosmos DB. Per esempi, vedere Modelli di Azure Resource Manager per Azure Cosmos DB.
Per progetto, i modelli di Azure Resource Manager non possono essere usati per eseguire la migrazione tra throughput provisionato e throughput autoscalato in una risorsa esistente.
Interfaccia della riga di comando di Azure
L'interfaccia della riga di comando di Azure può essere usata per effettuare il provisioning della velocità effettiva di scalabilità automatica in un nuovo database o in una risorsa a livello di contenitore per tutte le API di Azure Cosmos DB o per abilitare la scalabilità automatica in una risorsa esistente.
Azure PowerShell
Azure PowerShell può essere usato per effettuare il provisioning della velocità effettiva di scalabilità automatica in un nuovo database o in una risorsa a livello di contenitore per tutte le API di Azure Cosmos DB o per abilitare la scalabilità automatica in una risorsa esistente.
Passaggi successivi