33
votes

Is it possible to limit the maximum number of Functions that run in parallel?

I read the documentation and came across this:

When multiple triggering events occur faster than a single-threaded function runtime can process them, the runtime may invoke the function multiple times in parallel.

If a function app is using the Consumption hosting plan, the function app could scale out automatically. Each instance of the function app, whether the app runs on the Consumption hosting plan or a regular App Service hosting plan, might process concurrent function invocations in parallel using multiple threads.

The maximum number of concurrent function invocations in each function app instance varies based on the type of trigger being used as well as the resources used by other functions within the function app.

https://docs.microsoft.com/en-gb/azure/azure-functions/functions-reference#parallel-execution

I am using a Function on an App Service plan with an Event Hub input binding and only have a single Function within my Function App. If I can't limit it, does anyone know what the maximum number of concurrent function invocations will be for this kind of setup?

4

4 Answers

21
votes

There isn't a way to specify a maximum concurrency for Event Hubs triggered functions, but you can control batch size and fetching options as described here.

The maximum number of concurrent invocations may also vary depending on your workload and resource utilization.

If concurrency limits are needed, this is (currently) something you'd need to handle, and the following posts discuss some patterns you may find useful:

Throttling Azure Storage Queue processing in Azure Function App

Limiting the number of concurrent jobs on Azure Functions queue

16
votes

Just for reference, I came across here in my search for throttling. You can use the [Singleton] attribute on your function ensuring only one-at-a-time execution. Maybe not really what you were looking for and a very rigorous way of throttling, but still, it is an option.

https://docs.microsoft.com/en-us/azure/app-service/webjobs-sdk-how-to#singleton-attribute

5
votes

Microsoft has added a new setting which can be used to limit concurrency of function execution. The setting is WEBSITE_MAX_DYNAMIC_APPLICATION_SCALE_OUT and can be used to limit how many function instances will execute in parallel. However, according to Microsoft, it isn't fully implemented yet.

https://github.com/Azure/azure-functions-host/wiki/Configuration-Settings

1
votes

For those who are still interested: https://docs.microsoft.com/en-us/azure/azure-functions/event-driven-scaling#limit-scale-out

There's a way to limit the number of parallel execution by setting functionAppScaleLimit parameter.