配置语义模型横向扩展

你可以在 Power BI 服务中启用横向扩展,也可以使用 Power BI 数据集 REST API。 在配置语义模型之前,请阅读 Power BI 语义模型横向扩展概述。

在 Power BI 服务中启用横向扩展

若要在 Power BI 服务中为语义模型启用横向扩展,请执行以下步骤:

  1. 在 Power BI 服务中,使用要为其启用横向扩展的语义模型打开工作区。

  2. 选择该语义模型的更多选项图标 (...)。

  3. 从菜单中选择“设置”

  4. 在设置的页面中,启用“大型语义模型存储格式”(如果未启用)

  5. 启用“查询横向扩展”并选择“应用”。

    A screenshot showing how to enable scale out in Power BI service.

使用数据集 REST API 启用横向扩展

本部分介绍了如何使用 Power BI 数据集 REST API 来配置语义模型横向扩展。

获取 datasetId

请使用 Get-PowerBIDataset 获取 datasetId。 必须指定 workspaceId 和语义模型名称。

Login-PowerBI | Out-Null

$workspaceId = '<enter workspaceId>'

$datasetId = Get-PowerBIDataset -WorkspaceId $workspaceId `
    | Where{$_.Name -match "<enter semantic model name>"} `
    | Select-Object -ExpandProperty Id -First 1 `
    | ForEach-Object {$_.Guid}

Write-Host
Write-Host "Workspace Id: $workspaceId"
Write-Host "Dataset Id: $datasetId"

获取当前的横向扩展配置

在配置语义模型横向扩展之前,请确定当前配置。

###
# Get current scale-out configuration
###
Login-PowerBI | Out-Null

$workspaceId = '<enter workspaceId>'

$datasetId = Get-PowerBIDataset -WorkspaceId $workspaceId `
    | Where{$_.Name -match "<enter semantic model name>"} `
    | Select-Object -ExpandProperty Id -First 1 `
    | ForEach-Object {$_.Guid}

$response = Invoke-PowerBIRestMethod -Url "groups/$workspaceId/datasets/$datasetId" -Method Get | ConvertFrom-Json

$response.queryScaleOutSettings | Format-List

if ($response.queryScaleOutSettings.maxReadOnlyReplicas -eq -1 `
    -or $response.queryScaleOutSettings.maxReadOnlyReplicas -gt 0)
{
    Write-Host "Semantic model scale-out is enabled."
}
else
{
    Write-Host "Semantic model scale-out is disabled."
}

启用语义模型横向扩展

要启用语义模型横向扩展,请将 maxReadOnlyReplicas 设置为 -1,或任何非零值。 -1 的值允许 Power BI 创建 Power BI 容量支持的许多只读取副本。 还可以将副本计数明确设置为小于最大容量的一个值。 建议将 maxReadOnlyReplicas 设置为 -1

###
# Enable scale-out
###
Login-PowerBI | Out-Null

$workspaceId = '<enter workspaceId>'

$datasetId = Get-PowerBIDataset -WorkspaceId $workspaceId `
    | Where{$_.Name -match "<enter semantic model name>"} `
    | Select-Object -ExpandProperty Id -First 1 `
    | ForEach-Object {$_.Guid}

Invoke-PowerBIRestMethod -Url "groups/$workspaceId/datasets/$datasetId" `
    -Method Patch -Body '{ "queryScaleOutSettings": { "maxReadOnlyReplicas": -1 }}'

Invoke-PowerBIRestMethod -Url "groups/$workspaceId/datasets/$datasetId" -Method Get `
    | ConvertFrom-Json | Select-Object -ExpandProperty queryScaleOutSettings `
    | ForEach { 
        if($_.maxReadOnlyReplicas -eq -1)
        { 
            Write-Host "Success! Semantic model scale-out has been enabled."
        } else
        {
            Write-Host "Something went wrong! Semantic model scale-out is still disabled." -ForegroundColor Red
        }
     }

禁用语义模型横向扩展

要禁用语义模型横向扩展,请将 maxReadOnlyReplicas 设置为 0

###
# Disable scale-out
###
Login-PowerBI | Out-Null

$workspaceId = '<enter workspaceId>'

$datasetId = Get-PowerBIDataset -WorkspaceId $workspaceId `
    | Where{$_.Name -match "<enter semantic model name>"} `
    | Select-Object -ExpandProperty Id -First 1 `
    | ForEach-Object {$_.Guid}

Invoke-PowerBIRestMethod -Url "groups/$workspaceId/datasets/$datasetId" `
    -Method Patch -Body '{ "queryScaleOutSettings": { "maxReadOnlyReplicas": 0 }}'

Invoke-PowerBIRestMethod -Url "groups/$workspaceId/datasets/$datasetId" -Method Get `
    | ConvertFrom-Json | Select-Object -ExpandProperty queryScaleOutSettings `
    | ForEach { 
        if($_.maxReadOnlyReplicas -eq 0)
        { 
            Write-Host "Success! Semantic model scale-out has been disabled."
        } else
        {
            Write-Host "Something went wrong! Semantic model scale-out is still enabled." -ForegroundColor Red
        }
     }