Share via


Operazioni di velocità effettiva (UR/s) con l'interfaccia della riga di comando di Azure per un database o un grafo per Azure Cosmos DB - API per Gremlin

Se non si ha una sottoscrizione di Azure, creare un account Azure gratuito prima di iniziare.

Lo script in questo articolo crea un database Gremlin con velocità effettiva condivisa e un grafo Gremlin con velocità effettiva dedicata, quindi aggiorna la velocità effettiva per il database e il grafo. Lo script esegue quindi la migrazione dalla velocità effettiva standard alla velocità effettiva con scalabilità automatica e, al termine della migrazione, legge il valore della velocità effettiva con scalabilità automatica.

Prerequisiti

  • Questo articolo richiede la versione 2.30 o successiva. Eseguire az --version per trovare la versione. Se è necessario eseguire l'installazione o l'aggiornamento, vedere Installare l'interfaccia della riga di comando di Azure. Se si usa Azure Cloud Shell, la versione più recente è già installata.

Script di esempio

Avviare Azure Cloud Shell

Azure Cloud Shell è una shell interattiva gratuita che può essere usata per eseguire la procedura di questo articolo. Include strumenti comuni di Azure preinstallati e configurati per l'uso con l'account.

Per aprire Cloud Shell, basta selezionare Prova nell'angolo superiore destro di un blocco di codice. È anche possibile avviare Cloud Shell in una scheda separata del browser visitando https://shell.azure.com.

Quando si apre Cloud Shell, verificare che sia selezionato Bash per l'ambiente. Le sessioni successive useranno l'interfaccia della riga di comando di Azure in un ambiente Bash. Selezionare Copia per copiare i blocchi di codice, incollarli in Cloud Shell e premere Invio per eseguirli.

Accedere ad Azure

Cloud Shell viene autenticato automaticamente con l'account iniziale con cui è stato eseguito l'accesso. Usare lo script seguente per accedere usando una sottoscrizione diversa, sostituendo <Subscription ID> con l'ID sottoscrizione di Azure. Se non si ha una sottoscrizione di Azure, creare un account Azure gratuito prima di iniziare.

subscription="<subscriptionId>" # add subscription here

az account set -s $subscription # ...or use 'az login'

Per altre informazioni, vedere Impostare la sottoscrizione attiva oppure Accedere in modo interattivo

Eseguire lo script

# Throughput operations for a Gremlin API database and graph

# Variable block
let "randomIdentifier=$RANDOM*$RANDOM"
location="East US"
resourceGroup="msdocs-cosmosdb-rg-$randomIdentifier"
tag="throughput-gremlin-cosmosdb"
account="msdocs-account-cosmos-$randomIdentifier" #needs to be lower case
database="msdocs-db-gremlin-cosmos"
graph="msdocs-graph1-gremlin-cosmos"
partitionKey="/partitionKey"
originalThroughput=400
updateThroughput=500

# Create a resource group 
az group create --name $resourceGroup --location "$location" --tags $tag

# Create a Cosmos account for Gremlin API
echo "Creating $account"
az cosmosdb create --name $account --resource-group $resourceGroup --capabilities EnableGremlin

# Create Gremlin database with throughput
echo "Creating $database with $originalThroughput"
az cosmosdb gremlin database create --account-name $account --resource-group $resourceGroup --name $database --throughput $originalThroughput

# Create Gremlin graph with throughput 
echo "Creating $graph with $originalThroughput"
az cosmosdb gremlin graph create --account-name $account --resource-group $resourceGroup --database-name $database --name $graph --partition-key-path $partitionKey --throughput $originalThroughput

# Throughput operations for Gremlin API database
#   Read the current throughput
#   Read the minimum throughput
#   Make sure the updated throughput is not less than the minimum
#   Update the throughput
#   Migrate between standard (manual) and autoscale throughput
#   Read the autoscale max throughput

# Retrieve the current provisioned database throughput
az cosmosdb gremlin database throughput show --resource-group $resourceGroup --account-name $account --name $database --query resource.throughput -o tsv

# Retrieve the minimum allowable database throughput
minimumThroughput=$(az cosmosdb gremlin database throughput show --resource-group $resourceGroup --account-name $account --name $database --query resource.minimumThroughput -o tsv)

echo $minimumThroughput

# Make sure the updated throughput is not less than the minimum allowed throughput
if [ $updateThroughput -lt $minimumThroughput ]; then
    updateThroughput=$minimumThroughput
fi

# Update database throughput
echo "Updating $database throughput to $updateThroughput"
az cosmosdb gremlin database throughput update --account-name $account --resource-group $resourceGroup --name $database --throughput $updateThroughput

# Migrate the database from standard (manual) throughput to autoscale throughput
az cosmosdb gremlin database throughput migrate --account-name $account --resource-group $resourceGroup --name $database --throughput-type "autoscale"

# Retrieve current autoscale provisioned max database throughput
az cosmosdb gremlin database throughput show --resource-group $resourceGroup --account-name $account --name $database --query resource.autoscaleSettings.maxThroughput -o tsv

# Throughput operations for Gremlin API graph
#   Read the current throughput
#   Read the minimum throughput
#   Make sure the updated throughput is not less than the minimum
#   Update the throughput
#   Migrate between standard (manual) and autoscale throughput
#   Read the autoscale max throughput

# Retrieve the current provisioned graph throughput
az cosmosdb gremlin graph throughput show --resource-group $resourceGroup --account-name $account --database $database --name $graph --query resource.throughput -o tsv

# Retrieve the minimum allowable graph throughput
minimumThroughput=$(az cosmosdb gremlin graph throughput show --resource-group $resourceGroup --account-name $account --database $database --name $graph --query resource.minimumThroughput -o tsv)
echo $minimumThroughput

# Make sure the updated throughput is not less than the minimum allowed throughput
if [ $updateThroughput -lt $minimumThroughput ]; then
    updateThroughput=$minimumThroughput
fi

# Update graph throughput
echo "Updating $graph throughput to $updateThroughput"
az cosmosdb gremlin graph throughput update --resource-group $resourceGroup --account-name $account --database $database --name $graph --throughput $updateThroughput

# Migrate the graph from standard (manual) throughput to autoscale throughput
az cosmosdb gremlin graph throughput migrate --account-name $account --resource-group $resourceGroup --database $database --name $graph --throughput-type "autoscale"

# Retrieve the current autoscale provisioned max graph throughput
az cosmosdb gremlin graph throughput show --resource-group $resourceGroup --account-name $account --database $database --name $graph --query resource.autoscaleSettings.maxThroughput -o tsv

Pulire le risorse

Usare il comando seguente per rimuovere il gruppo di risorse e tutte le risorse associate usando il comando az group delete, a meno che queste risorse non siano ancora necessarie. La creazione e l'eliminazione di alcune di queste risorse può richiedere tempo.

az group delete --name $resourceGroup

Informazioni di riferimento per l'esempio

Questo script usa i comandi seguenti. Ogni comando della tabella include collegamenti alla documentazione specifica del comando.

Comando Note
az group create Consente di creare un gruppo di risorse in cui sono archiviate tutte le risorse.
az cosmosdb create Crea un account Azure Cosmos DB.
az cosmosdb gremlin database create Crea un database di Azure Cosmos DB per Gremlin.
az cosmosdb gremlin graph create Crea un grafo di Azure Cosmos DB per Gremlin.
az cosmosdb gremlin database throughput update Aggiorna il valore di UR/s per un database di Azure Cosmos DB for Gremlin.
az cosmosdb gremlin graph throughput update Aggiorna il valore di UR/s per un grafo di Azure Cosmos DB for Gremlin.
az cosmosdb gremlin database throughput migrate Esegue la migrazione della velocità effettiva per un database di Azure Cosmos DB for Gremlin.
az cosmosdb gremlin graph throughput migrate Esegue la migrazione della velocità effettiva per un grafo di Azure Cosmos DB for Gremlin.
az group delete Consente di eliminare un gruppo di risorse incluse tutte le risorse annidate.

Passaggi successivi

Per altre informazioni sull'interfaccia della riga di comando di Azure Cosmos DB, vedere la relativa documentazione.