Azure Blob 触发功能延迟且本地过于拥挤

问题描述 投票:0回答:1

我正在使用 C# 和 .NET8。 Azure 函数版本 4 我有一个 Blob 触发器 Azure 函数在 Azure 云中运行,没有出现任何问题。该函数使用我的存储库中的 GitHub Actions 进行更新。当我想添加新功能时,我会在部署之前在本地测试它们。 问题是,现在,当我在本地运行该函数时,它开始触发自本地运行以来发生的所有 blob 更改。这通常需要很多时间。当它最终完成触发时,我运行新的更改,并且需要几个小时才能运行。

以前,只需几秒钟。如何减少触发延迟?

c# .net azure-functions azure-blob-trigger
1个回答
0
投票

正如@Mason A提到的,如果您连接到部署环境中使用的同一个存储帐户

  1. 使用单独的存储:
  • 在现有存储帐户中创建新的存储帐户或新容器。
  • 这种隔离有助于防止部署环境出现进一步问题。
  1. 使用替代选项:
  • 使用 Azure Functions 的 Blob 存储触发器有时会导致执行延迟,因为触发器会轮询 Blob 容器以获取更新。

  • 要减少这些情况下的延迟,请使用同一容器的事件订阅来触发该函数。

  • 请参阅文章


我通过在同一存储帐户中创建两个容器在我的环境中进行了相同的测试,并且能够毫无延迟地运行该函数。

  • 在存储帐户中创建了两个容器:

本地输出:

Azure Functions Core Tools
Core Tools Version:       4.0.5611 Commit hash: N/A +591b8aec842e333a87ea9e23ba390bb5effe0655 (64-bit)
Function Runtime Version: 4.31.1.22191

[2024-04-05T12:45:41.720Z] Found C:\Users\uname\Source\Repos\FunctionApp.csproj. Using for user secrets file configuration.
[2024-04-05T12:46:14.567Z] Azure Functions .NET Worker (PID: 26804) initialized in debug mode. Waiting for debugger to attach...
[2024-04-05T12:46:14.791Z] Worker process started and initialized.

Functions:

        Function1: blobTrigger

For detailed output, run func with --verbose flag.
[2024-04-05T12:46:19.651Z] Host lock lease acquired by instance ID '000000000000000000000000F72731CC'.
[2024-04-05T12:46:29.201Z] Executing 'Functions.Function1' (Reason='New blob detected(LogsAndContainerScan): samples-workitems/Hello World.txt', Id=881042fd-f65c-4254-841c-ceb6f414003e)
[2024-04-05T12:46:29.208Z] Trigger Details: MessageId: b377cda0-1de5-4524-8e14-ae735f4fa67b, DequeueCount: 1, InsertedOn: 2024-04-05T12:46:28.000+00:00, BlobCreated: 2024-04-05T12:46:24.000+00:00, BlobLastModified: 2024-04-05T12:46:24.000+00:00
[2024-04-05T12:46:31.849Z] C# Blob trigger function Processed blob
 Name: Hello World.txt
 Data: Hello World
[2024-04-05T12:46:31.921Z] Executed 'Functions.Function1' (Succeeded, Id=881042fd-f65c-4254-841c-ceb6f414003e, Duration=3164ms)
© www.soinside.com 2019 - 2024. All rights reserved.