具有 Javascript 运行时的 Azure 函数读取 httptrigger 请求的速度很慢

标签 azure azure-functions azure-functions-runtime

我使用 javascript 运行时和 HttpTrigger 将数据 (4MB) 作为 gipped 请求发送到 azure 函数。在函数中,我解压缩数据并对其进行处理。在函数中运行代码需要 6-7 秒,但请求的往返时间几乎需要 60 秒。我知道上传请求需要一些时间,但我没想到会有这么大的延迟。如何调试时间的去向?

这不是冷启动问题,因为请求始终需要 60 秒。

最佳答案

据我所知,Azure Functions 尚不支持附加 App Insights Profiler,但您可以添加自己的遥测数据。

如果时间花在 Azure 函数运行时内,这不一定有帮助,但如果瓶颈出现在解压缩/处理期间,则可能有助于缓解:

https://learn.microsoft.com/en-us/azure/application-insights/application-insights-custom-operations-tracking?toc=/azure/azure-monitor/toc.json#outgoing-dependencies-tracking

自定义依赖项跟踪的一般方法是:

  • 调用 TelemetryClient.StartOperation(扩展)方法,该方法填充关联所需的 DependencyTelemetry 属性和一些其他属性(开始时间戳、持续时间)。
  • 在 DependencyTelemetry 上设置其他自定义属性,例如名称和您需要的任何其他上下文。
  • 进行依赖项调用并等待。
  • 完成后使用 StopOperation 停止操作。
  • 处理异常情况。

文档中的示例:

public async Task RunMyTaskAsync()
{
    using (var operation = telemetryClient.StartOperation<DependencyTelemetry>("task 1"))
    {
        try 
        {
            var myTask = await StartMyTaskAsync();
            // Update status code and success as appropriate.
        }
        catch(...) 
        {
            // Update status code and success as appropriate.
        }
    }
}

关于具有 Javascript 运行时的 Azure 函数读取 httptrigger 请求的速度很慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52965378/

相关文章:

c# - 在 Azure Function 中使用配置管理器

azure - Azure Functions 中的 System.Data.SqlClient 4.6.0

azure - 根据具有相同消息id的多条消息仅选取azure服务总线队列中的最新消息

excel - 如何在azure数据工厂中将excel文件转换为csv

Azure powershell session 立即超时

azure - Azure 函数模板中缺少 .NET 7 选项

azure - 将元数据添加到 Azure 函数中的跟踪

azure - 如果 Key Vault 中的 secret 更新,是否应该重新启动 Azure Functions 应用程序?

python - 从另一个 Azure Function 调用 Azure Function

azure - 当 azure 函数返回值时发出警报