Azure Functions:了解多个应用上下文中的更改源

Azure Functions: Understanding Change Feed in the context of multiple apps

根据下图https://docs.microsoft.com/en-us/azure/cosmos-db/change-feed-processor,两台主机之间至少分布了4个分区键范围。我在这张图中难以理解的是主机和消费者之间的区别。在 Azure Functions 的上下文中,可以说主机是 Function 应用程序而消费者是 active/warm 实例吗?

我想创建一个包含 N 多个 Function 应用程序的设置,每个应用程序有 0-200 个活动实例(取决于工作量)。同时,我想读书Change Feed。如果我在每个应用程序中使用具有相同连接字符串和租用容器的 CosmosDBTrigger,这是自动处理还是我需要手动实施?

您链接的文档主要针对更改源处理器,但 Azure Functions 绑定实际上在下面运行更改源处理器。

当只使用 CFP 时,它可能更容易理解,因为您主要控制实例和分布,但我会尝试将其映射到 Functions。

文档中提到了一个deployment unit概念:

A single change feed processor deployment unit consists of one or more instances with the same processorName and lease container configuration. You can have many deployment units where each one has a different business flow for the changes and each deployment unit consisting of one or more instances.

For example, you might have one deployment unit that triggers an external API anytime there is a change in your container. Another deployment unit might move data, in real time, each time there is a change. When a change happens in your monitored container, all your deployment units will get notified.

Functions中的部署单元是Function App。一个 Function App 可以跨越多个实例。因此,该 Function App 部署中的每个 instance/host 都将充当可用 host/consumer.

再往下,这篇文章谈到了 dynamic scaling,它基本上说的是,在部署单元(Function App)内,租约将得到平均分配。因此,如果您有 20 个租约和 10 个 Function App 实例,那么每个实例将拥有 2 个租约并独立于其他实例处理它们。

关于该文章的一个重要说明是,缩放可以实现更高的 CPU 池,但不一定具有更高的并行度。

如文档所述,即使在单个实例上,CFP 也会处理和读取它在独立任务上拥有的每个租约。问题是,所有这些并行处理共享相同的 CPU,因此如果您当前看到实例具有 CPU thread/bottleneck.

,则添加更多实例会有所帮助

现在,在您的示例中,您想要拥有 N 个功能应用程序,我假设每个应用程序都在做不同的事情。基本上,微服务部署会触发任何更改,但会执行不同的任务或触发不同的业务流程。

这个other article涵盖了那个。基本上,您可以让每个 Function App 使用单独的 Lease 集合(让受监视的集合相同),或者您可以共享租约集合,但为每个 Function App 部署使用不同的 LeaseCollectionPrefix。如果您将共享租赁集合的功能应用程序的数量很高,请检查租赁集合上的 RU 使用情况,因为您可能需要增加它(文章中有关于它的注释)。