简体   繁体   中英

Azure function Service Bus Trigger concurrency

I'm developing an Azure Function that executes several operations in Dynamics 365 CRM. I don't fully understand how Azure Functions concurrency works. I have a Consumption Plan, my Azure Function has a function inside that is triggered by a Service Bus message.

When I tested it the first time, the service bus received around 200 messages and the app started processing a lot of messages at the same time, making a huge load of requests to dynamics 365 that couldn't handle them. So in the Azure Portal I managed to set the max number of instances to 1, but still the function was processing many messages at one time. What's the best way to set a limit to that? Using maxConcurrentCalls in host.json? Using maxConcurrentSessions in host.json? Using WEBSITE_MAX_DYNAMIC_APPLICATION_SCALE_OUT in the app configs?

Also, what's the difference between setting maxConcurrentCalls at 10, and 1 function instance or setting it at 5 with 2 function instances?

maxConcurrentCalls is the attribute configured in host.json for the Azure Functions Service Bus Trigger.

By default, the runtime of Functions processes multiple messages concurrently (default value - 16). Set maxConcurrentCalls to 1 for setting up to process only a single queue or topic message at a time by the runtime.

Also, maxConcurrentCalls is the max no. of concurrent calls to the callback that should be initiate per scaled instance.


maxConcurrentSessions - Maximum No. of Sessions handled concurrently per scaled instance.

This setting only applies for functions that receive a single message at a time.

For the requirement of only one message need to be processed at a time per instance than you can use above configuration in the host.json .

If your requirement is Singleton support for Functions to ensure only one function running at a time, then you need to configure this .


WEBSITE_MAX_DYNAMIC_APPLICATION_SCALE_OUT

This setting has no default limit, which states the max no. of instances that the app can scale out to.

  1. Not to Scale out the function and to run only in one instance, set WEBSITE_MAX_DYNAMIC_APPLICATION_SCALE_OUT to 1
  2. In addition to this setting, you need to set maxConcurrentCalls to 1.

Few References for more information:

  1. Azure Function to process only single message at one time
  2. Azure Functions - WEBSITE_MAX_DYNAMIC_APPLICATION_SCALE_OUT and batchSize - how can I get the desired concurrency
  3. azure servicebus maxConcurrentCalls totally ignored
  4. Official documentation of host.json settings in Azure Function Service Bus Trigger explains about maxConcurrentCalls , maxConcurrentSessions
  5. Official Doc explains about WEBSITE_MAX_DYNAMIC_APPLICATION_SCALE_OUT

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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