你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

Azure 数字孪生中的查询单元

本文介绍了查询单位、Azure 数字孪生如何使用查询单位,以及如何在 Azure 数字孪生中查找查询单位消耗量。

Azure 数字孪生查询单元 (QU)是一个按需计算单元,用于通过查询 API 执行 Azure 数字孪生查询

它抽象掉执行 Azure 数字孪生支持的查询操作所需的 CPU、IOPS 和内存等系统资源,允许你改为在查询单元中跟踪使用情况。

执行查询所消耗的查询单元数量受以下因素影响:

  • 查询的复杂性
  • 结果集的大小(因此,一个返回 10 个结果的查询将比一个只返回一个结果的类似复杂度的查询消耗更多的 QU)

本文介绍如何了解查询单元以及如何跟踪查询单元消耗量。

在 Azure 数字孪生中查找查询单元消耗量

使用 Azure 数字孪生查询 API 运行查询时,可以检查响应标头以跟踪查询使用的 QU 数。 在从 Azure 数字孪生发送回的响应中查找“query-charge”。

通过 Azure 数字孪生 SDK,可以从可分页响应中提取 query-charge 标头。 本部分介绍如何查询数字孪生体,以及如何循环访问可分页响应来提取 query-charge 标头。

以下代码片段演示如何提取调用查询 API 时产生的查询费用。 它首先循环访问响应页面以访问 query-charge 标头,然后循环访问每个页面中的数字孪生体结果。

using Azure;
using Azure.DigitalTwins.Core;
using System;

namespace DigitalTwins_Samples
{
    public class GetQueryChargesSample
    {
        async public void Run(DigitalTwinsClient client)
        {
            AsyncPageable<BasicDigitalTwin> asyncPageableResponseWithCharge = client.QueryAsync<BasicDigitalTwin>("SELECT * FROM digitaltwins");
            int pageNum = 0;

            // The "await" keyword here is required, as a call is made when fetching a new page.

            await foreach (Page<BasicDigitalTwin> page in asyncPageableResponseWithCharge.AsPages())
            {
                Console.WriteLine($"Page {++pageNum} results:");

                // Extract the query-charge header from the page

                if (QueryChargeHelper.TryGetQueryCharge(page, out float queryCharge))
                {
                    Console.WriteLine($"Query charge was: {queryCharge}");
                }

                // Iterate over the twin instances.

                // The "await" keyword is not required here, as the paged response is local.

                foreach (BasicDigitalTwin twin in page.Values)
                {
                    Console.WriteLine($"Found digital twin '{twin.Id}'");
                }
            }
        }
    }
}

后续步骤

若要详细了解如何查询 Azure 数字孪生,请访问:

可以在 Azure 数字孪生服务限制中找到与 Azure 数字孪生查询相关的限制。