Share via


Opérations de débit (RU/s) avec Azure CLI sur une base de données ou un graphe pour Azure Cosmos DB - API pour Gremlin

Si vous n’avez pas d’abonnement Azure, créez un compte gratuit Azure avant de commencer.

Le script dans cet article crée une base de données Gremlin avec un débit partagé et un graphe Gremlin avec un débit dédié, puis met à jour le débit pour la base de données et le graphe. Le script migre ensuite du débit standard à un débit avec mise à l’échelle automatique, puis lit la valeur de ce débit après sa migration.

Prérequis

  • Cet article nécessite la version 2.30 ou une version ultérieure. Exécutez az --version pour trouver la version. Si vous devez installer ou mettre à niveau, voir Installer Azure CLI. Si vous utilisez Azure Cloud Shell, la version la plus récente est déjà installée.

Exemple de script

Lancement d’Azure Cloud Shell

Azure Cloud Shell est un interpréteur de commandes interactif et gratuit que vous pouvez utiliser pour exécuter les étapes de cet article. Il contient des outils Azure courants préinstallés et configurés pour être utilisés avec votre compte.

Pour ouvrir Cloud Shell, sélectionnez simplement Essayer en haut à droite d’un bloc de code. Vous pouvez aussi lancer Cloud Shell dans un onglet distinct du navigateur en accédant à https://shell.azure.com.

Quand Cloud Shell s’ouvre, vérifiez que Bash est sélectionné pour votre environnement. Les sessions ultérieures utiliseront Azure CLI dans un environnement Bash. Sélectionnez Copier pour copier les blocs de code, collez-les dans Cloud Shell, puis appuyez sur Entrée pour les exécuter.

Connexion à Azure

Cloud Shell est automatiquement authentifié sous le compte initial utilisé pour la connexion. Utilisez le script suivant pour vous connecter avec un autre abonnement, en remplaçant <Subscription ID> par votre ID d’abonnement Azure. Si vous n’avez pas d’abonnement Azure, créez un compte gratuit Azure avant de commencer.

subscription="<subscriptionId>" # add subscription here

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

Pour plus d’informations, consultez Définir l’abonnement actif ou Se connecter de manière interactive

Exécuter le 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

Nettoyer les ressources

Utilisez la commande suivante pour supprimer le groupe de ressources et toutes les ressources associées à celui-ci à l’aide de la commande az group delete, sauf si vous avez toujours besoin de ces ressources. La création, ainsi que la suppression, de certaines de ces ressources peut prendre du temps.

az group delete --name $resourceGroup

Informations de référence sur l’exemple

Ce script utilise les commandes suivantes. Chaque commande du tableau renvoie à une documentation spécifique.

Commande Notes
az group create Crée un groupe de ressources dans lequel toutes les ressources sont stockées.
az cosmosdb create Crée un compte Azure Cosmos DB.
az cosmosdb gremlin database create Crée une base de données Azure Cosmos DB pour Gremlin.
az cosmosdb gremlin graph create Crée un graphe Azure Cosmos DB pour Gremlin.
az cosmosdb gremlin database throughput update Met à jour les unités de requête/s pour une base de données Azure Cosmos DB pour Gremlin.
az cosmosdb gremlin graph throughput update Met à jour les unités de requête/s pour un graphe Azure Cosmos DB pour Gremlin.
az cosmosdb gremlin database throughput migrate Migre le débit pour une base de données Azure Cosmos DB pour Gremlin.
az cosmosdb gremlin graph throughput migrate Migre le débit pour un graphe Azure Cosmos DB pour Gremlin.
az group delete Supprime un groupe de ressources, y compris toutes les ressources imbriquées.

Étapes suivantes

Pour plus d’informations sur l’interface CLI Azure Cosmos DB, consultez la documentation sur l’interface CLI Azure Cosmos DB.