Share via


Doorvoerbewerkingen (RU/s) met Azure CLI voor een database of grafiek voor Azure Cosmos DB - API voor Gremlin

Als u geen Azure-abonnement hebt, kunt u een gratis Azure-account maken voordat u begint.

Met het script in dit artikel maakt u een Gremlin-database met gedeelde doorvoer en een Gremlin-grafiek met toegewezen doorvoer, waarna de doorvoer voor zowel de database als de grafiek wordt bijgewerkt. Met het script wordt de migratie van standaarddoorvoer naar doorvoer met automatische schaalaanpassing uitgevoerd en de waarde van doorvoer met automatische schaalaanpassing gelezen nadat de migratie is voltooid.

Vereisten

  • Voor dit artikel is versie 2.30 of hoger vereist. Voer az --version uit om de versie te bekijken. Als u Azure CLI 2.0 wilt installeren of upgraden, raadpleegt u Azure CLI 2.0 installeren. Als u Azure Cloud Shell gebruikt, is de nieuwste versie al geïnstalleerd.

Voorbeeldscript

Azure Cloud Shell starten

Azure Cloud Shell is een gratis interactieve shell waarmee u de stappen in dit artikel kunt uitvoeren. In deze shell zijn algemene Azure-hulpprogramma's vooraf geïnstalleerd en geconfigureerd voor gebruik met uw account.

Als u Cloud Shell wilt openen, selecteert u Proberen in de rechterbovenhoek van een codeblok. U kunt Cloud Shell ook openen in een afzonderlijk browsertabblad door naar https://shell.azure.com te gaan.

Wanneer Cloud Shell wordt geopend, controleert u of Bash is geselecteerd voor uw omgeving. Volgende sessies gebruiken Azure CLI in een Bash-omgeving, selecteer Kopiëren om de codeblokken te kopiëren, plak deze in Cloud Shell en druk op Enter om deze uit te voeren.

Aanmelden bij Azure

Cloud Shell wordt automatisch geverifieerd onder het eerste account waarmee is aangemeld. Gebruik het volgende script om u aan te melden met een ander abonnement, waarbij u <Subscription ID> uw Azure-abonnements-id vervangt. Als u geen Azure-abonnement hebt, kunt u een gratis Azure-account maken voordat u begint.

subscription="<subscriptionId>" # add subscription here

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

Zie Voor meer informatie het instellen van een actief abonnement of het interactief aanmelden

Het script uitvoeren

# 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

Resources opschonen

Gebruik de volgende opdracht om de resourcegroep en alle bijbehorende resources te verwijderen met behulp van de opdracht az group delete - tenzij u deze resources voortdurend nodig hebt. Het kan even duren voordat sommige van deze resources zijn gemaakt en dat deze kunnen worden verwijderd.

az group delete --name $resourceGroup

Voorbeeldverwijzing

In dit script worden de volgende opdrachten gebruikt. Elke opdracht in de tabel is een koppeling naar specifieke documentatie over de opdracht.

Command Aantekeningen
az group create Hiermee wordt een resourcegroep gemaakt waarin alle resources worden opgeslagen.
az cosmosdb create Hiermee wordt een Azure Cosmos DB-account gemaakt.
az cosmosdb gremlin database create Hiermee maakt u een Azure Cosmos DB voor Gremlin-database.
az cosmosdb gremlin graph create Hiermee maakt u een Azure Cosmos DB voor Gremlin-grafiek.
az cosmosdb gremlin database throughput update RU/s bijwerken voor een Azure Cosmos DB voor Gremlin-database.
az cosmosdb gremlin graph throughput update RU/s bijwerken voor een Azure Cosmos DB voor Gremlin-grafiek.
az cosmosdb gremlin database throughput migrate Doorvoer migreren voor een Azure Cosmos DB voor Gremlin-database.
az cosmosdb gremlin graph throughput migrate Doorvoer migreren voor een Azure Cosmos DB voor Gremlin-grafiek.
az group delete Hiermee verwijdert u een resourcegroep met inbegrip van alle ingesloten resources.

Volgende stappen

Raadpleeg de documentatie van Azure Cosmos DB CLI voor meer informatie over de Azure Cosmos DB CLI.