我正在开发一个 Azure Function,该函数在 Dynamics 365 CRM 中执行多项操作。 我不完全理解 Azure Functions 并发的工作原理。 我有一个消费计划,我的 Azure 函数内部有一个由服务总线消息触发的函数。
当我第一次测试它时,服务总线收到大约 200 条消息,并且应用程序开始同时处理大量消息,向 Dynamics 365 发出大量无法处理的请求。 因此,在 Azure 门户中,我设法将最大实例数设置为 1,但该函数仍然一次处理许多消息。 对此设置限制的最佳方法是什么? 在 host.json 中使用 maxConcurrentCalls? 在 host.json 中使用 maxConcurrentSessions? 在应用配置中使用 WEBSITE_MAX_DYNAMIC_APPLICATION_SCALE_OUT?
此外,将 maxConcurrentCalls 设置为 10 和 1 个函数实例或将其设置为 5 和 2 个函数实例有什么区别?
最佳答案
maxConcurrentCalls 是在 host.json
中为 Azure Functions 服务总线触发器配置的属性。
默认情况下,Functions 的运行时会同时处理多个消息(默认值 - 16)。将 maxConcurrentCalls
设置为 1,以设置运行时一次仅处理单个队列或主题消息。
此外,maxConcurrentCalls
是最大数量。对每个缩放实例应启动的回调的并发调用数。
maxConcurrentSessions - 每个缩放实例同时处理的最大 session 数。
This setting only applies for functions that receive a single message at a time.
对于每个实例一次只需要处理一条消息的要求,您可以在 host.json
中使用上述配置。
如果您的要求是函数单例支持,以确保一次只运行一个函数,那么您需要配置this .
<小时/>WEBSITE_MAX_DYNAMIC_APPLICATION_SCALE_OUT
此设置没有默认限制,它规定了最大数量。应用程序可以扩展到的实例数。
- 为了不横向扩展该函数并仅在一个实例中运行,请将
WEBSITE_MAX_DYNAMIC_APPLICATION_SCALE_OUT
设置为 1 - 除了此设置之外,您还需要将
maxConcurrentCalls
设置为 1。
有关更多信息的引用文献:
- Azure Function to process only single message at one time
- Azure Functions -
WEBSITE_MAX_DYNAMIC_APPLICATION_SCALE_OUT
and batchSize - how can I get the desired concurrency - azure servicebus
maxConcurrentCalls
totally ignored - Official documentation of
host.json
settings in Azure Function Service Bus Trigger explains aboutmaxConcurrentCalls
,maxConcurrentSessions
- Official Doc explains about
WEBSITE_MAX_DYNAMIC_APPLICATION_SCALE_OUT
关于Azure函数服务总线触发器并发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71578572/