40

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://learn.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?

Community
  • 1
  • 1
Chris
  • 3,113
  • 5
  • 24
  • 46

4 Answers4

23

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

Fabio Cavalcante
  • 12,328
  • 3
  • 35
  • 43
  • Thanks Fabio! Are there any plans to include this type of functionality? – Chris May 30 '17 at 21:48
  • 1
    Yes. This is definitely something we want to address as part of the product in the future. I don't have an ETA for that at this point, but a lot of the work to make this happen is currently in progress. – Fabio Cavalcante May 30 '17 at 21:49
  • @FabioCavalcante is there an update for 2020 on that work in progress? (I'll keep searching, but this is still the first hit google came up with) – stmax Jun 24 '20 at 07:18
  • I don't know why but it does not work to me. I modified the host.json as in the file on Github you linked. "batchSize": 1, still my blob trigger gets triggered more than 10times in parallel... – nicolass Jun 06 '23 at 13:29
23

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://learn.microsoft.com/en-us/azure/app-service/webjobs-sdk-how-to#singleton-attribute

Fowl
  • 4,940
  • 2
  • 26
  • 43
6

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

  • Thanks for adding that helpful link Bryan. – Chris Nov 19 '19 at 10:24
  • 3
    Great call, the documentation has moved to https://learn.microsoft.com/en-gb/azure/azure-functions/functions-app-settings and is now supported in preview – jondow Feb 06 '20 at 09:03
  • Have anybody tried this in production yet? This feature would really help us out in our architecture for supporting some legacy stuff, but if it is unstable we can't justified using it ... – Ng Sek Long Jun 07 '20 at 14:40
3

For those who are still interested: https://learn.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.