Condividi tramite


Operazioni di velocità effettiva (UR/s) con PowerShell per un database o un grafo per Azure Cosmos DB - API per Gremlin

SI APPLICA A: Gremlin

Nota

È consigliabile usare il modulo Azure Az PowerShell per interagire con Azure. Per iniziare, vedere Installare Azure PowerShell. Per informazioni su come eseguire la migrazione al modulo AZ PowerShell, vedere Eseguire la migrazione di Azure PowerShell da AzureRM ad Az.

Questo esempio richiede Azure PowerShell Az 5.4.0 o versioni successive. Eseguire Get-Module -ListAvailable Az per determinare le versioni installate. Se è necessario installarlo, vedere Installare il modulo Azure PowerShell.

Eseguire Connect-AzAccount per accedere ad Azure.

Misurare la velocità effettiva

# Reference: Az.CosmosDB | https://docs.microsoft.com/powershell/module/az.cosmosdb
# --------------------------------------------------
# Purpose
# Get database or graph throughput
# --------------------------------------------------
# Variables - ***** SUBSTITUTE YOUR VALUES *****
$resourceGroupName = "myResourceGroup" # Resource Group must already exist
$accountName = "myaccount" # Must be all lower case
$databaseName = "myDatabase"
$graphName = "myGraph"
# --------------------------------------------------

Write-Host "Get database shared throughput"
Get-AzCosmosDBGremlinDatabaseThroughput -ResourceGroupName $resourceGroupName `
    -AccountName $accountName -Name $databaseName

Write-Host "Get graph dedicated throughput"
Get-AzCosmosDBGremlinGraphThroughput -ResourceGroupName $resourceGroupName `
    -AccountName $accountName -DatabaseName $databaseName `
    -Name $graphName

Aggiornare la velocità effettiva

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

$throughput = Get-AzCosmosDBGremlinGraphThroughput `
    -ResourceGroupName $resourceGroupName `
    -AccountName $accountName -DatabaseName $databaseName `
    -Name $graphName

$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-AzCosmosDBGremlinGraphThroughput -ResourceGroupName $resourceGroupName `
        -AccountName $accountName -DatabaseName $databaseName `
        -Name $graphName -Throughput $newRUs
}

Eseguire la migrazione della velocità effettiva

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

Write-Host "Migrate database with standard throughput to autoscale throughput."
Invoke-AzCosmosDBGremlinDatabaseThroughputMigration -ResourceGroupName $resourceGroupName `
    -AccountName $accountName -Name $databaseName -ThroughputType Autoscale

Write-Host "Migrate database with autoscale throughput to standard throughput."
Invoke-AzCosmosDBGremlinDatabaseThroughputMigration -ResourceGroupName $resourceGroupName `
    -AccountName $accountName -Name $databaseName -ThroughputType Manual

Write-Host "Migrate graph with standard throughput to autoscale throughput."
Invoke-AzCosmosDBGremlinGraphThroughputMigration -ResourceGroupName $resourceGroupName `
    -AccountName $accountName -DatabaseName $databaseName -Name $graphName -ThroughputType Autoscale

Write-Host "Migrate graph with autoscale throughput to standard throughput."
Invoke-AzCosmosDBGremlinGraphThroughputMigration -ResourceGroupName $resourceGroupName `
    -AccountName $accountName -DatabaseName $databaseName -Name $graphName -ThroughputType Manual

Pulire la distribuzione

Dopo l'esecuzione dello script di esempio, è possibile usare il comando seguente per rimuovere il gruppo di risorse e tutte le risorse ad esso associate.

Remove-AzResourceGroup -ResourceGroupName "myResourceGroup"

Spiegazione dello script

Questo script usa i comandi seguenti. Ogni comando della tabella include collegamenti alla documentazione specifica del comando.

Comando Note
Azure Cosmos DB
Get-AzCosmosDBGremlinDatabaseThroughput Ottiene il valore della velocità effettiva del database dell'API per Gremlin.
Get-AzCosmosDBGremlinGraphThroughput Ottiene il valore della velocità effettiva del grafo dell'API per Gremlin.
Update-AzCosmosDBGremlinDatabaseThroughput Aggiorna il valore della velocità effettiva del database dell'API per Gremlin.
Update-AzCosmosDBGremlinGraphThroughput Aggiorna il valore della velocità effettiva del grafo dell'API per Gremlin.
Invoke-AzCosmosDBGremlinDatabaseThroughputMigration Esegue la migrazione della velocità effettiva del database dell'API per Gremlin.
Invoke-AzCosmosDBGremlinGraphThroughputMigration Esegue la migrazione della velocità effettiva del grafo dell'API per Gremlin.
Gruppi di risorse di Azure
Remove-AzResourceGroup Consente di eliminare un gruppo di risorse incluse tutte le risorse annidate.

Passaggi successivi

Per altre informazioni su Azure PowerShell, vedere la documentazione di Azure PowerShell.