Share via


Operaciones de rendimiento (RU/s) con la CLI de Azure para una tabla para Azure Cosmos DB for Table

SE APLICA A: Table

En el script de este artículo, se crea una tabla de API para Table y, a continuación, se actualiza el rendimiento de la tabla. A continuación, el script migra del rendimiento estándar a escalado automático y, a continuación, lee el valor del rendimiento de escalado automático una vez que se ha migrado.

Si no tiene una suscripción a Azure, cree una cuenta gratuita de Azure antes de empezar.

Requisitos previos

  • En este artículo, se requiere la versión 2.12.1 o posterior. Ejecute az --version para encontrar la versión. Si necesita instalarla o actualizarla, vea Instalación de la CLI de Azure. Si usa Azure Cloud Shell, ya está instalada la versión más reciente.

Script de ejemplo

Inicio de Azure Cloud Shell

Azure Cloud Shell es un shell interactivo gratuito que puede usar para ejecutar los pasos de este artículo. Tiene las herramientas comunes de Azure preinstaladas y configuradas para usarlas en la cuenta.

Para abrir Cloud Shell, seleccione Pruébelo en la esquina superior derecha de un bloque de código. También puede ir a https://shell.azure.com para iniciar Cloud Shell en una pestaña independiente del explorador.

Cuando se abra Cloud Shell, compruebe que Bash está seleccionado para el entorno. En las sesiones siguientes se usará la CLI de Azure en un entorno de Bash, seleccione Copiar para copiar los bloques de código, péguelos en Cloud Shell y, luego, presione Entrar para ejecutarlos.

Inicio de sesión en Azure

Cloud Shell se autentica de forma automática en la cuenta inicial con la que ha iniciado sesión. Use el script siguiente para iniciar sesión con otra suscripción, y reemplace <Subscription ID> con el id. de la suscripción de Azure. Si no tiene una suscripción a Azure, cree una cuenta gratuita de Azure antes de empezar.

subscription="<subscriptionId>" # add subscription here

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

Para más información, vea Establecimiento de la suscripción activa o Inicio de sesión de forma interactiva

Ejecute el script.

# Throughput operations for a Table API table

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

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

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

# Create a Table API Table with autoscale
echo "Create $table with $maxThroughput"
az cosmosdb table create --account-name $account --resource-group $resourceGroup --name $table --throughput $originalThroughput

# Throughput operations for Table 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 table throughput show --name $table --resource-group $resourceGroup --account-name $account --query resource.throughput -o tsv

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

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

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

Limpieza de recursos

Use el comando siguiente para quitar el grupo de recursos y todos los recursos asociados con él mediante el comando az group delete, a menos que tenga una necesidad constante de estos recursos. Algunos de estos recursos pueden tardar un tiempo en crearse, así como en eliminarse.

az group delete --name $resourceGroup

Referencia de ejemplo

Este script usa los siguientes comandos. Cada comando de la tabla crea un vínculo a documentación específica del comando.

Get-Help Notas
az group create Crea un grupo de recursos en el que se almacenan todos los recursos.
az cosmosdb create Crea una cuenta de Azure Cosmos DB.
az cosmosdb table create Crea una tabla de API para Table para Azure Cosmos DB.
az cosmosdb table throughput update Actualiza el rendimiento de una tabla de Table API para Azure Cosmos DB.
az cosmosdb table throughput migrate Migra el rendimiento de una tabla de Table API de Azure Cosmos DB.
az group delete Elimina un grupo de recursos, incluidos todos los recursos anidados.

Pasos siguientes

Para más información, consulte la documentación de la CLI de Azure Cosmos DB.