Compartir por


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

SE APLICA A: Table

Nota

Se recomienda usar el módulo Azure Az de PowerShell para interactuar con Azure. Para comenzar, consulte Instalación de Azure PowerShell. Para más información sobre cómo migrar al módulo Az de PowerShell, consulte Migración de Azure PowerShell de AzureRM a Az.

Este ejemplo requiere Azure PowerShell Az 5.4.0 o una versión posterior. Ejecute Get-Module -ListAvailable Az para ver qué versiones están instaladas. Si necesita instalarlo, consulte Instalación del módulo de Azure PowerShell.

Ejecute Connect AzAccount para iniciar sesión en Azure.

Obtención de rendimiento

# Reference: Az.CosmosDB | https://docs.microsoft.com/powershell/module/az.cosmosdb
# --------------------------------------------------
# Purpose
# Get RU/s throughput for Azure Cosmos DB Table API table
# --------------------------------------------------
# Variables - ***** SUBSTITUTE YOUR VALUES *****
$resourceGroupName = "myResourceGroup" # Resource Group must already exist
$accountName = "myaccount" # Must be all lower case
$tableName = "myTable"
# --------------------------------------------------

Get-AzCosmosDBTableThroughput -ResourceGroupName $resourceGroupName `
    -AccountName $accountName -Name $tableName

Actualización del rendimiento

# Reference: Az.CosmosDB | https://docs.microsoft.com/powershell/module/az.cosmosdb
# --------------------------------------------------
# Purpose
# Update Table throughput
# --------------------------------------------------
# Variables - ***** SUBSTITUTE YOUR VALUES *****
$resourceGroupName = "myResourceGroup" # Resource Group must already exist
$accountName = "myaccount" # Must be all lower case
$tableName = "myTable"
$newRUs = 500
# --------------------------------------------------

$throughput = Get-AzCosmosDBTableThroughput -ResourceGroupName $resourceGroupName `
    -AccountName $accountName -Name $tableName

$currentRUs = $throughput.Throughput
$minimumRUs = $throughput.MinimumThroughput

Write-Host "Current throughput is $currentRUs. Minimum allowed throughput is $minimumRUs."

if ([int]$newRUs -lt [int]$minimumRUs) {
    Write-Host "Requested new throughput of $newRUs is less than minimum allowed throughput of $minimumRUs."
    Write-Host "Using minimum allowed throughput of $minimumRUs instead."
    $newRUs = $minimumRUs
}

if ([int]$newRUs -eq [int]$currentRUs) {
    Write-Host "New throughput is the same as current throughput. No change needed."
}
else {
    Write-Host "Updating throughput to $newRUs."

    Update-AzCosmosDBTableThroughput -ResourceGroupName $resourceGroupName `
        -AccountName $accountName -Name $tableName `
        -Throughput $newRUs
}

Migración de capacidad de proceso

# Reference: Az.CosmosDB | https://docs.microsoft.com/powershell/module/az.cosmosdb
# --------------------------------------------------
# Purpose
# Migrate a table to autoscale or standard (manual) throughput
# --------------------------------------------------
# Variables - ***** SUBSTITUTE YOUR VALUES *****
$resourceGroupName = "myResourceGroup" # Resource Group must already exist
$accountName = "myaccount" # Must be all lower case
$tableName = "myTable"
# --------------------------------------------------

Write-Host "Migrate table with standard throughput to autoscale throughput."
Invoke-AzCosmosDBTableThroughputMigration -ResourceGroupName $resourceGroupName `
    -AccountName $accountName -Name $tableName -ThroughputType Autoscale

Write-Host "Migrate table with autoscale throughput to standard throughput."
Invoke-AzCosmosDBTableThroughputMigration -ResourceGroupName $resourceGroupName `
    -AccountName $accountName -Name $tableName -ThroughputType Manual

Limpieza de la implementación

Después de ejecutar el script de ejemplo, se puede usar el comando siguiente para quitar el grupo de recursos y todos los recursos asociados.

Remove-AzResourceGroup -ResourceGroupName "myResourceGroup"

Explicación del script

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
Azure Cosmos DB
Get-AzCosmosDBTableThroughput Obtiene el valor del rendimiento de la tabla especificada de la API para Table.
Update-AzCosmosDBMongoDBCollectionThroughput Actualiza el valor del rendimiento de la tabla de la API para Table.
Invoke-AzCosmosDBTableThroughputMigration Migra el rendimiento de una tabla de la API para Table.
Grupos de recursos de Azure
Remove-AzResourceGroup Elimina un grupo de recursos, incluidos todos los recursos anidados.

Pasos siguientes

Para más información sobre Azure PowerShell, consulte la documentación de Azure PowerShell.