Share via


Durchsatzvorgänge (RU/s) mit der Azure CLI für einen Keyspace oder eine Tabelle für Azure Cosmos DB: API für Cassandra

GILT FÜR: Cassandra

Das Skript in diesem Artikel erstellt einen Cassandra-Keyspace mit gemeinsam genutztem Durchsatz sowie eine Cassandra-Tabelle mit dediziertem Durchsatz und aktualisiert dann den Durchsatz für Keyspace und Tabelle. Anschließend führt das Skript die Migration vom standardmäßigen zum automatisch skalierten Durchsatz durch, und nach Abschluss der Migration wird dann der Wert des automatisch skalierten Durchsatzes gelesen.

Wenn Sie kein Azure-Abonnement haben, erstellen Sie ein kostenloses Azure-Konto, bevor Sie beginnen.

Voraussetzungen

  • Verwenden Sie die Bash-Umgebung in Azure Cloud Shell. Weitere Informationen finden Sie unter Schnellstart für Bash in Azure Cloud Shell.

  • Wenn Sie CLI-Referenzbefehle lieber lokal ausführen, installieren Sie die Azure CLI. Wenn Sie Windows oder macOS ausführen, sollten Sie die Azure CLI in einem Docker-Container ausführen. Weitere Informationen finden Sie unter Ausführen der Azure CLI in einem Docker-Container.

    • Wenn Sie eine lokale Installation verwenden, melden Sie sich mithilfe des Befehls az login bei der Azure CLI an. Führen Sie die in Ihrem Terminal angezeigten Schritte aus, um den Authentifizierungsprozess abzuschließen. Informationen zu anderen Anmeldeoptionen finden Sie unter Anmelden mit der Azure CLI.

    • Installieren Sie die Azure CLI-Erweiterung beim ersten Einsatz, wenn Sie dazu aufgefordert werden. Weitere Informationen zu Erweiterungen finden Sie unter Verwenden von Erweiterungen mit der Azure CLI.

    • Führen Sie az version aus, um die installierte Version und die abhängigen Bibliotheken zu ermitteln. Führen Sie az upgrade aus, um das Upgrade auf die aktuelle Version durchzuführen.

  • Für diesen Artikel ist mindestens die Azure CLI-Version 2.12.1 erforderlich. Führen Sie az --version aus, um die Version zu ermitteln. Informationen zum Durchführen einer Installation oder eines Upgrades finden Sie bei Bedarf unter Installieren der Azure CLI. Bei Verwendung von Azure Cloud Shell ist die aktuelle Version bereits installiert.

Beispielskript

Starten von Azure Cloud Shell

Azure Cloud Shell ist eine kostenlose interaktive Shell, mit der Sie die Schritte in diesem Artikel durchführen können. Sie verfügt über allgemeine vorinstallierte Tools und ist für die Verwendung mit Ihrem Konto konfiguriert.

Wählen Sie zum Öffnen von Cloud Shell oben rechts in einem Codeblock einfach die Option Ausprobieren. Sie können Cloud Shell auch auf einem separaten Browsertab starten, indem Sie zu https://shell.azure.com navigieren.

Überprüfen Sie nach dem Öffnen von Cloud Shell, ob Bash für Ihre Umgebung ausgewählt ist. In den folgenden Sitzungen wird die Azure CLI in einer Bash-Umgebung verwendet. Wählen Sie Kopieren aus, um die Codeblöcke zu kopieren. Fügen Sie sie in Cloud Shell ein, und drücken Sie die EINGABETASTE, um sie auszuführen.

Anmelden bei Azure

Cloud Shell wird automatisch unter dem Konto authentifiziert, mit dem die Anmeldung anfänglich erfolgt ist. Verwenden Sie das folgende Skript, um sich mit einem anderen Abonnement anzumelden, und ersetzen Sie <Subscription ID> durch Ihre Azure-Abonnement-ID. Wenn Sie kein Azure-Abonnement haben, erstellen Sie ein kostenloses Azure-Konto, bevor Sie beginnen.

subscription="<subscriptionId>" # add subscription here

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

Weitere Informationen finden Sie unter Festlegen des aktiven Abonnements oder unter Interaktives Anmelden.

Ausführen des Skripts

# Throughput operations for a Cassandra keyspace and table

# Variable block
let "randomIdentifier=$RANDOM*$RANDOM"
location="East US"
resourceGroup="msdocs-cosmosdb-rg-$randomIdentifier"
tag="serverless-casandra-cosmosdb"
account="msdocs-account-cosmos-$randomIdentifier" #needs to be lower case
keySpace="keyspace1"
table="table1"
originalThroughput=400
updateThroughput=500

# Create a resource group
echo "Creating $resourceGroup in $location..."
az group create --name $resourceGroup --location "$location"

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

# Create Cassandra keyspace
echo "Creating $keySpace with $originalThroughput"
az cosmosdb cassandra keyspace create --account-name $account --resource-group $resourceGroup --name $keySpace --throughput $originalThroughput

# Define the schema for the table
printf ' 
{
    "columns": [
        {"name": "columnA","type": "uuid"}, 
        {"name": "columnB","type": "text"}
    ],
    "partitionKeys": [{"name": "columnA"}]
}' > "schema-$randomIdentifier.json"

# Create the Cassandra table
echo "Creating $table with $originalThroughput"
az cosmosdb cassandra table create --account-name $account --resource-group $resourceGroup --keyspace-name $keySpace --name $table --throughput $originalThroughput --schema @schema-$randomIdentifier.json

# Clean up temporary schema file
rm -f "schema-$randomIdentifier.json"

# Throughput operations for Cassandra API keyspace
#   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 keyspace throughput
az cosmosdb cassandra keyspace throughput show --account-name $account --resource-group $resourceGroup --name $keySpace --query resource.throughput -o tsv

# Retrieve the minimum allowable keyspace throughput
minimumThroughput=$(az cosmosdb cassandra keyspace throughput show --account-name $account --resource-group $resourceGroup --name $keySpace --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 keyspace throughput
echo "Updating $keyspace throughput to $updateThroughput"
az cosmosdb cassandra keyspace throughput update --account-name $account --resource-group $resourceGroup --name $keySpace --throughput $updateThroughput

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

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

# Throughput operations for Cassandra API table
#   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 table throughput
az cosmosdb cassandra table throughput show --account-name $account --resource-group $resourceGroup --keyspace-name $keySpace --name $table --query resource.throughput -o tsv

# Retrieve the minimum allowable table throughput
minimumThroughput=$(az cosmosdb cassandra table throughput show --account-name $account --resource-group $resourceGroup --keyspace-name $keySpace --name $table --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 table throughput
echo "Updating $table throughput to $updateThroughput"
az cosmosdb cassandra table throughput update --account-name $account --resource-group $resourceGroup --keyspace-name $keySpace --name $table --throughput $updateThroughput

# Migrate the table from standard (manual) throughput to autoscale throughput
az cosmosdb cassandra table throughput migrate --account-name $account --resource-group $resourceGroup --keyspace-name $keySpace --name $table --throughput-type "autoscale"

# Retrieve the current autoscale provisioned max table throughput
az cosmosdb cassandra table throughput show --account-name $account --resource-group $resourceGroup --keyspace-name $keySpace --name $table --query resource.autoscaleSettings.maxThroughput -o tsv

Bereinigen von Ressourcen

Verwenden Sie den folgenden Befehl, um die Ressourcengruppe und alle zugehörigen Ressourcen mit dem Befehl az group delete zu entfernen, es sei denn, Sie benötigen diese Ressourcen weiterhin. Bei einigen dieser Ressourcen kann das Erstellen wie auch das Löschen eine Weile dauern.

az group delete --name $resourceGroup

Beispielreferenz

Das Skript verwendet die folgenden Befehle. Jeder Befehl in der Tabelle ist mit der zugehörigen Dokumentation verknüpft.

Get-Help Notizen
az group create Erstellt eine Ressourcengruppe, in der alle Ressourcen gespeichert sind.
az cosmosdb create Erstellt ein Konto für Azure Cosmos DB.
az cosmosdb cassandra keyspace create Erstellt einen Azure Cosmos DB-Cassandra-Keyspace.
az cosmosdb cassandra table create Erstellt eine Azure Cosmos DB-Cassandra-Tabelle.
az cosmosdb cassandra keyspace throughput update Aktualisieren der Anforderungseinheiten pro Sekunde (RU/s) für einen Azure Cosmos DB-Cassandra-Keyspace.
az cosmosdb cassandra table throughput update Aktualisieren der Anforderungseinheiten pro Sekunde (RU/s) für eine Azure Cosmos DB-Cassandra-Tabelle.
az cosmosdb cassandra keyspace throughput migrate Migrieren des Durchsatzes für einen Azure Cosmos DB-Cassandra-Keyspace.
az cosmosdb cassandra table throughput migrate Migrieren des Durchsatzes für eine Azure Cosmos DB-Cassandra-Tabelle.
az group delete Löscht eine Ressourcengruppe einschließlich aller geschachtelten Ressourcen.

Nächste Schritte

Weitere Informationen zur Azure Cosmos DB-CLI finden Sie in der Dokumentation zur Azure Cosmos DB-CLI.