Azure函数在30秒后死亡,无法同时运行多个调用

发布于 2025-02-10 02:23:49 字数 1522 浏览 1 评论 0原文

我使用.NET C#消费计划(也在专用计划中测试),由HTTP触发器触发,目前我对其行为感到非常困惑

- 我只是意识到我似乎只有问题,我对其 行为感到非常困惑如果我使用Azure Portal运行。如果我从浏览器称呼它,它将运行完美。因此,也许这只是Microsoft的故障。...如果从浏览器调用时可以正常运行,我不在乎该门户是否死亡。因此,请专注于并发行为。

第一件事是:它不能超过30秒。 在下图中,您可以看到,我只有一个非常简单的任务。如果我将其设置为低于30秒。它运行良好。但是,如果我将其设置为30秒以上,例如图片中的内容,它将返回503个错误。

- - 上述:完整的代码

#r "Newtonsoft.Json"

using System.Net;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using Newtonsoft.Json;

public static async Task<IActionResult> Run(HttpRequest req, ILogger log)
{
    log.LogInformation("C# HTTP trigger function processed a request.");
    var datenow = DateTime.Now.ToString("yyyy/mm/dd hh:mm:ss");

    await Task.Delay(32000);

    return new OkObjectResult("OK..." + Environment.GetEnvironmentVariable("WEBSITE_INSTANCE_ID") + " Start date time: " + datenow );
}

- 上升2:您可以将任务提高到40000,因此可以更轻松地复制问题。另外,如果您想复制,请多次尝试,因为它可以成功并随机失败。

第二个怪异的行为是,Azure函数似乎是按顺序处理的,而我的期望是它应该同时处理事物。例如。我调用上述功能,该功能具有任务。使用与浏览器的2个分离的选项卡,为10秒,2次。我注意到第二个电话只在第一个开始后运行

是正常的上述事项。还是我对某些东西进行了错误配置?我想要的是,我想要一个功能可以超过30秒,越长。另外,我希望函数同时运行。

注意:我尝试了诊断和解决问题,但没有给我任何想法。

I have an Azure Function using .NET C# consumption plan (also tested in dedicated plan), triggered by HTTP trigger, and currently I am very confusing with its behaviors

--UPDATE 3: I just realized that it seems like I only have the problem if I use the run through Azure Portal. It runs perfectly if I call it from a browser. So perhaps it is just Microsoft fault.... If it can run normally when it is called from a browser, I don't care if the Portal dies. So please concentrate on the concurrency behavior.

First thing is: it cannot run for more than 30 seconds.
In the below picture, you can see that, I only have a very simple Task.Delay. If I set it to lower than 30 seconds. It runs fine. But if I set it to more than 30 seconds, like what is in the picture, it will returns 503 errors.

enter image description here

--UPDATE: THE FULL CODE

#r "Newtonsoft.Json"

using System.Net;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using Newtonsoft.Json;

public static async Task<IActionResult> Run(HttpRequest req, ILogger log)
{
    log.LogInformation("C# HTTP trigger function processed a request.");
    var datenow = DateTime.Now.ToString("yyyy/mm/dd hh:mm:ss");

    await Task.Delay(32000);

    return new OkObjectResult("OK..." + Environment.GetEnvironmentVariable("WEBSITE_INSTANCE_ID") + " Start date time: " + datenow );
}

--UPDATE 2: You can raise the Task.Delay to 40000, so the problem can be reproduced easier. Also, if you want to reproduce, please try it multiple time, as it can success and fail randomly.

The second weird behavior is that the Azure Function seems to process things sequentially, while my expectation is that it should process things concurrently. For example. I call the above function, which has a task.delay of 10 second, 2 times, using 2 separated tab from my browser. I noticed that the second call only ran after the first one start
enter image description here

Are those above things normal. Or did I misconfigured something? What I want is that I want a function can be longer than 30 seconds, the longer the better. Also, I want functions to be concurrently run.

Note: I tried the Diagnosis and solve problem but it didn't give me any idea into this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文