You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Azure Durable Functions中测量触发到返回的响应时间

测量Azure Durable Functions从触发到响应的总时间(Python v2 + 免费层)

针对你要研究编排与活动函数间数据大小对响应时间的影响,以下是在Azure门户和Application Insights中的具体测量方法:

一、Azure门户日志直接查询基础耗时

  1. 进入你的Function App,左侧导航选择「监控」>「日志」
  2. 使用Kusto查询获取HTTP触发请求的总耗时:
    requests
    | where operation_Name == "你的HTTP触发函数名称"
    | where success == true
    | project 时间戳=timestamp, 总耗时(毫秒)=duration, 事务ID=operation_Id, 函数名=operation_Name
    | sort by timestamp desc
    
    这里的duration字段就是从HTTP请求进入到响应返回的完整耗时。
  3. 若要关联编排函数的执行细节,可通过operation_Id关联traces表,查看编排完成时间与请求开始时间的差值:
    requests
    | where operation_Name == "你的HTTP触发函数名称"
    | join kind=inner (
        traces
        | where message contains "Orchestration completed"
        | project operation_Id, 编排结束时间=timestamp
    ) on operation_Id
    | project 请求开始时间=timestamp, 总耗时(毫秒)=duration, 编排结束时间, 实际流程耗时=编排结束时间 - 请求开始时间
    

二、Application Insights端到端追踪与批量分析

Application Insights能提供更细粒度的调用链追踪,适合你对比不同数据大小的耗时差异:

  1. 确保Function App已启用Application Insights(免费层可使用Basic版,免费额度足够测试)
  2. 进入对应的Application Insights资源,左侧选「性能」>「事务搜索」
  3. 输入HTTP触发函数名或事务ID筛选目标请求,点击事务详情即可查看完整调用链:从HTTP请求发起、编排函数启动、活动函数调用到响应返回的每个阶段耗时,顶部的总时长就是你需要的端到端时间。
  4. 为了批量分析数据大小的影响,可在Python代码中添加自定义维度标记数据大小:
    import logging
    from azure.functions import HttpRequest, HttpResponse
    from azure.durable_functions import DurableOrchestrationClient
    
    async def main(req: HttpRequest, starter: str) -> HttpResponse:
        client = DurableOrchestrationClient(starter)
        # 计算请求体数据大小
        data_size = len(req.get_body())
        # 添加自定义维度到日志
        logging.info(f"Request data size: {data_size} bytes", extra={"custom_dimensions": {"data_size_bytes": data_size}})
        # 启动编排
        instance_id = await client.start_new(req.route_params["functionName"], None, req.get_body())
        return client.create_check_status_response(req, instance_id)
    
  5. 回到Application Insights的日志页面,用Kusto查询分组统计不同数据大小的耗时:
    requests
    | where operation_Name == "你的HTTP触发函数名称"
    | join kind=inner (
        traces
        | where customDimensions.data_size_bytes != ""
        | project operation_Id, 数据大小=toint(customDimensions.data_size_bytes)
    ) on operation_Id
    | summarize 平均耗时(毫秒)=avg(duration), 最大耗时(毫秒)=max(duration) by 数据大小
    | sort by 数据大小 asc
    
    这个查询会按数据大小分组,输出对应平均和最大耗时,方便你做对比分析。

注意事项

  • 免费层Function App有5分钟执行时长限制和资源配额,测试时避免超出,否则会影响数据准确性
  • 测试前先预热函数实例(连续触发几次),排除冷启动对耗时的干扰
  • 多次测试取平均值,保证数据的可靠性

内容的提问来源于stack exchange,提问作者TY00

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.07 16:04:55