简体   繁体   English

Azure Function完成时间长怎么办?

[英]What to do when Azure Function takes long time to complete?

I'm new to Azure Functions and trying to do a new project.我是 Azure 函数的新手,正在尝试做一个新项目。 I've run into some issues when my function takes too long to process the data.当我的 function 处理数据的时间过长时,我遇到了一些问题。 I'm using a BlobTrigger and every time someone uploads a new blob I need the data in the blob to analyze some things using other Microsoft Services.我正在使用 BlobTrigger,每次有人上传新的 Blob 时,我都需要 Blob 中的数据来使用其他 Microsoft 服务分析某些内容。

Here is the code for my Azure Function:这是我的 Azure Function 的代码:

[StorageAccount("BlobConnectionString")]
public class AnalyzeAzureBlob
{
    private readonly IAnalyzeResult analyzeResult;

    public AnalyzeAzureBlob(IAnalyzeResult analyzeResult)
    {
        this.analyzeResult = analyzeResult;
    }
    [FunctionName("AnalyzeAzureBlob")]
    public void Run(
        [BlobTrigger("samples-analyze/{name}")]Stream inputBlob,
        [Blob("analyzed/{name}", FileAccess.Write)] Stream outputBlob,
        string name,
        ILogger log)
    {

        log.LogInformation($"C# Blob trigger function Processed blob\n Name:{name} \n Size: {inputBlob.Length} Bytes");

        try
        {
            this.analyzeResult.AnalyzeData(inputBlob, outputBlob);
            log.LogInformation("The file has been analyzed");
        }
        catch (Exception ex)
        {
            log.LogError("The analyze failed", ex);
            Console.WriteLine(ex.ToString());
        }
    }
}

The function runs as it should but sometimes the timeout is reached and it fails if the blob contains a large amount of data. function 正常运行,但有时会超时,如果 blob 包含大量数据,则会失败。 How can I avoid timeouts and wait for the whole process to complete using Azure Functions?如何使用 Azure 函数避免超时并等待整个过程完成?

Note: I've read about Azure Durable Functions but have a hard time understanding how to implement them and use them in my code.注意:我已阅读有关 Azure 持久函数的信息,但很难理解如何在我的代码中实现和使用它们。

How can I avoid timeouts and wait for the whole process to complete using Azure Functions?如何使用 Azure 函数避免超时并等待整个过程完成?

As you not mentioned which hosting plan using for the Azure Function App.正如您没有提到 Azure Function 应用程序使用哪个托管计划。 But if the request processing takes long time and giving the timeout exceptions then change to Premium or dedicated hosting plan of Azure Function App.但是,如果请求处理需要很长时间并给出超时异常,则更改为 Azure Function App 的高级或专用托管计划

  • Implement chunks (File Chunking) which means the blob file could be processed in a chunks format using Azure Function Blob Trigger and a sample workaround given by Andrew Hoefling in his blog.实现块(文件分块),这意味着可以使用 Azure Function Blob 触发器和 Andrew Hoefling 在他的博客中给出的示例解决方法以块格式处理 blob 文件。

I've read about Azure Durable Functions but have a hard time understanding how to implement them and use them in my code.我已经阅读了有关 Azure 持久函数的信息,但很难理解如何在我的代码中实现它们并使用它们。

Two Functions - One is for Orchestrator in Durable Function and the other is for Blob trigger that would be to start/trigger running the durable orchestrator function.两个功能 - 一个用于 Durable Function 中的 Orchestrator,另一个用于 Blob 触发器,用于启动/触发运行持久协调器 function。

For example:例如:

Blob Trigger :斑点触发器

[FunctionName("StartOrchestratorBlobTriggerFunction")]
public async Task StartOrchestratorBlobTriggerFunction(
[BlobTrigger("sample-workitems/{name}", Connection = "<Storage-Account-Name>")] Stream myBlob,
             string name,
             [OrchestrationClient] DurableOrchestrationClient durableOrchestrationClient,
             ILogger log)
    {
        // Obtain your blob content, deserialize it if necessary, and provide it to the orchestrator rather than the stream as seen below.
        await durableOrchestrationClient.StartNewAsync("YourNewDurableFunction", myBlob);   
    }

Durable Function :耐用 Function

[FunctionName("YourDurableFunction")]
 public async Task YourDurableFunction(
     [OrchestrationTrigger] DurableOrchestrationContextBase orchestrationContext,
     ILogger logger)
{
    // here Calling the activity functions
}

The function should be finished as quick as possible, you should take the long task logic into a different solution, triggered by queue message, so the Azure function only enqueues the message into the queue and finish instantly. function 应尽快完成,您应该将长任务逻辑放入由队列消息触发的不同解决方案中,因此 Azure ZC1C425268E68385D1AB5074C17A94F14 立即将消息排入队列并完成。

I had the exact use case here .我在这里有确切的用例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 正则表达需要很长时间才能完成 - Regex takes a long time to complete Azure ServiceBusProcessor 需要很长时间才能停止 - Azure ServiceBusProcessor takes a long time to stop C#桌面图表绘制完成需要很长时间 - C# desktop chart draw complete takes long time 我该怎么做才能使这个 foreach 循环运行得更快,因为它需要很长时间才能执行? - What can I do to make this foreach loop run faster as it takes long time to execute? GetGeopositionAsync需要太长时间才能完成 - GetGeopositionAsync takes too long to complete Azure devops 私有 nuget 找了半天 package - Azure devops private nuget takes a long time to find package Swagger需要很长时间才能开始。 可能是什么原因? - Swagger takes long time to start. What could be the reasons? 处理需要“很长时间”才能完成的程序的正确方法是什么? - What is the correct way to deal with procedures that take a “long time” to complete? 我需要什么样的计算才能完成一台PC所需的时间,而对于几台PC则不需要那么长时间? - What kind of calculations would I need that takes a while for a pc to complete but not as long for several pcs? 在执行时将Any()与IQueryable List一起使用会花费很长时间? - using Any() with IQueryable List takes long time when executing?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM