简体   繁体   English

耐用 Function,延迟不准确以秒为单位

[英]Durable Function, delay not accurate in seconds

I'm trying to create a durable function with a delay of x seconds.我正在尝试创建一个延迟x秒的耐用 function。 Unfortunately, the bigger x is, the inaccuracy increases.不幸的是, x越大,误差越大。

I'm using the example shown in the MS docs :我正在使用MS 文档中显示的示例:

function.json: function.json:

{
  "bindings": [
    {
      "name": "context",
      "type": "orchestrationTrigger",
      "direction": "in"
    }
  ],
  "scriptFile": "../dist/function/index.js"
}
const deadline = moment.utc(context.df.currentUtcDateTime).add(60, 'seconds');
yield context.df.createTimer(deadline.toDate());
context.df.callActivity("SendBillingEvent");

If I add 60 seconds to the timer, there's an extra delay of ~20 seconds.如果我在计时器上增加 60 秒,则会有大约 20 秒的额外延迟。 Are durable function inherently just inaccurate or is there another way to activate a function using a delay?耐用的 function 本质上是不准确的,还是有其他方法可以使用延迟激活 function?


the logs shows:日志显示:

[2021-02-20T09:23:03.878Z] the timer is: n {
[2021-02-20T09:23:03.878Z]   isCompleted: true,
[2021-02-20T09:23:03.878Z]   isFaulted: false,
[2021-02-20T09:23:03.878Z]   action: {
[2021-02-20T09:23:03.878Z]     fireAt: 2021-02-20T09:22:43.503Z,
[2021-02-20T09:23:03.878Z]     isCanceled: false,
[2021-02-20T09:23:03.878Z]     actionType: 5
[2021-02-20T09:23:03.879Z]   },
[2021-02-20T09:23:03.879Z]   result: undefined,
[2021-02-20T09:23:03.879Z]   timestamp: '2021-02-20T09:21:43.662554Z',
[2021-02-20T09:23:03.879Z]   id: 0,
[2021-02-20T09:23:03.879Z]   exception: undefined,
[2021-02-20T09:23:03.879Z]   completionIndex: 5,
[2021-02-20T09:23:03.879Z]   wasYielded: false
[2021-02-20T09:23:03.879Z] }

I think it is inaccurate because of the way timers are created.我认为这是不准确的,因为计时器的创建方式。 When using the standard Azure Storage durability provider, a scheduled message on a Storage queue is used.使用标准 Azure 存储持久性提供程序时,使用存储队列上的计划消息。 Essentially DF adds a message to the queue that is scheduled to become visible at the time you set.本质上,DF 会向队列中添加一条消息,该消息计划在您设置的时间变为可见。

The instance running the orchestrator checks for new messages periodically by polling the queue.运行协调器的实例通过轮询队列定期检查新消息。 So there is most likely a delay between when the message becomes visible and the next message polling request.因此,在消息变得可见和下一个消息轮询请求之间很可能存在延迟。 Then when it receives the message, DF has to load the instance history from the history table and then execute the orchestrator again.然后当它收到消息时,DF 必须从历史表中加载实例历史,然后再次执行协调器。 This also adds some overhead.这也增加了一些开销。

The Durable Task framework that DF uses does allow different durability providers to be used. DF 使用的 Durable Task 框架确实允许使用不同的持久性提供程序。 Some of those might offer much more precise timers.其中一些可能会提供更精确的计时器。 But as far as I know, you can't configure DF to use a different one.但据我所知,您不能将 DF 配置为使用不同的。

You can also try adjusting the polling frequency for messages: https://docs.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-perf-and-scale#queue-polling .您还可以尝试调整消息的轮询频率: https://docs.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-perf-and-scale#queue-polling Specifically, there is a maxQueuePollingInterval property in host.json that defaults to 00:00:30 (30 seconds).具体来说,host.json 中有一个maxQueuePollingInterval属性,默认为00:00:30 (30 秒)。 So when DF checks the queue and sees there are no messages, it increases the next polling time until it reaches the max set here.所以当 DF 检查队列并发现没有消息时,它会增加下一次轮询时间,直到达到此处设置的最大值。 Check the host.json docs here to see where to set the property: https://docs.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-bindings#host-json .在此处查看 host.json 文档以查看在何处设置属性: https://docs.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-bindings#host-json

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM