随着时间的推移,Azure Durable Function 变得越来越慢

Azure Durable Function getting slower and slower over time

我的 Azure Durable Function(Runtime V3) 平均每天获得 300 万个事件。当它运行两三个星期时,它会变得越来越慢。当我删除 Durable Function Framework 使用的两个 table 存储(历史和实例)时,它变得越来越好并且按预期工作。我在消费计划中托管了我的函数应用程序。在我的函数应用程序中,我也使用了 Durabel 实体。在我的代码中,我也使用子协调器来实现扇出机制。

在工作量大的情况下会不会出现这个问题?我是否需要不时清除那些 table 存储,或者我是否需要删除我的持久实体函数中已完成实体的状态?

谁来帮帮我

是的,您应该通过调用 PurgeInstanceHistoryAsync method. See a similar post on how to do this:

自己执行定期清理

另请检查代码中可能存在的任何循环或 Monitor 模式。 任何循环逻辑(如 foreachforwhile 循环)将从初始启动状态重放。虽然 Durable Function 重放架构在执行此操作方面非常高效,但我们编写的代码可能未针对重复迭代进行优化。

Durable Monitor Pattern is almost an Anti-Pattern. The concept is OK but it is easily misinterpreted and is open to abuse. It is designed for a low-frequency loop that polls an endpoint either for a set number of iterations or up until a finite time, or of course when the state of the endpoint being monitoried has changed. That state change will be the trigger to perform the rest of the operation.

It is NOT an example of how to use general or high frequency looping structures in Durable functions

It is NOT and example of how to implement a traditional HTTP endpoint reporting monitor in an infinite loop (while(true)) style, perhaps to record changes into a data store over time.

如果您的持久函数逻辑具有可能涉及多次迭代的迭代器,请考虑将迭代步骤迁移到使用 Eternal Orchestration 模式的子编排