Reputation: 61
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?
Upvotes: 6
Views: 9323
Reputation:
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.
WEBSITE_MAX_DYNAMIC_APPLICATION_SCALE_OUT
to 1maxConcurrentCalls
to 1.Few References for more information:
WEBSITE_MAX_DYNAMIC_APPLICATION_SCALE_OUT
and batchSize - how can I get the desired concurrencymaxConcurrentCalls
totally ignoredhost.json
settings in Azure Function Service Bus Trigger explains about maxConcurrentCalls
, maxConcurrentSessions
WEBSITE_MAX_DYNAMIC_APPLICATION_SCALE_OUT
Upvotes: 5