I have an Azure Function app on the Linux Consumption Plan that has two queue triggers. Both queue triggers have the batchSize
parameter set to 1
because they can both use about 500 MB of memory each and I don't want to exceed the 1.5GB memory limit, so they should only be allowed to pick up one message at a time.
If I want to allow both of these queue triggers to run concurrently, but don't want them to scale beyond that, is setting the functionAppScaleLimit
to 2
enough to achieve that?
Edit: added new examples, thank you @Hury Shen for providing the framework for these examples
Please see @Hury Shen's answer below for more details. I've tested three queue trigger scenarios. All use the following legend:
QueueTrigger with no functionAppScaleLimit
QueueTrigger with functionAppScaleLimit
set to 2
QueueTrigger with functionAppScaleLimit
set to 1
For now, I think I'm going to stick with the last example, but in the future I think I can safely set my functionAppScaleLimit
to 2
or 3
if I upgrade to the premium plan. I also am going to test two queue triggers that listen to different storage queues with a functionAppScaleLimit
of 2
, but I suspect the safest thing for me to do is to create separate Azure Function apps for each queue trigger in that scenario.
Edit 2: add examples for two queue triggers within one function app
Here are the results when using two queue triggers within one Azure Function that are listening on two different storage queues. This is the legend for both queue triggers:
Both queue triggers running concurrently with functionAppScaleLimit
set to 2
Both queue triggers running concurrently with functionAppScaleLimit
set to 1
In the example where two queue triggers are running concurrently with functionAppScaleLimit
set to 2
it looks like the scale limit is not working. Can someone from Microsoft please explain? There is no warning in the official documentation (https://docs.microsoft.com/en-us/azure/azure-functions/functions-scale#limit-scale-out) that this setting is in preview mode, yet we can clearly see that the Azure Function is scaling out to 4 instances when the limit is set to 2. In the following example, it looks like the limit is being respected, but the functionality is not what I want and we still see the waiting that is present in @Hury Shen's answer.
Conclusion
To limit concurrency and control scaling in Azure Functions with queue triggers, you must limit your Azure Function to use one queue trigger per function app and use the batchSize
and functionAppScaleLimit
settings. You will encounter race conditions and waiting that may lead to timeouts if you use more than one queue trigger.