Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't my Azure Function scale up?

For a test, I created a new function app. I added two functions, one was an http trigger that when invoked, pushed 500 messages to a queue. The other, a queue trigger to read the messages. The queue trigger function code, was setup to read a message and randomly sleep from 1 to 30 seconds. This was intended to simulate longer running tasks.

I invoked the http trigger to create the messages, then watched the que fill up (messages were processed by the other trigger). I also wired up app insights to this function app, but I did not see is scale beyond 1 server.

Do Azure functions scale up soley on the # of messages in the que?

Also, I implemented these functions in Powershell.

like image 429
Doug Finke Avatar asked Apr 13 '26 15:04

Doug Finke


2 Answers

If you're running in the Azure Functions consumption plan, we monitor both the length and the throughput of your queue to determine whether additional VM resources are needed.

Note that a single function app instance can process multiple queue messages concurrently without needing to scale across multiple VMs. So if all 500 messages can be consumed relatively quickly (again, in the consumption plan), then it's possible that you won't scale at all.

The exact algorithm for scaling isn't published (it's subject to lots of tweaking), but generally speaking you can expect the system to automatically scale you out if messages are getting added to the queue faster than your functions can process them. Your app will also scale out if the latency of the first message in the queue is continuously increasing (meaning, messages are sitting idle and not getting processed). The time between VMs getting added is usually in the tens of seconds.

There are some thresholds based on queue count as well. For example, the system tries to ensure that there is at least 1 VM for every 1K queue messages, but usually the scale decisions are based on message throughput as I described earlier.

like image 104
Chris Gillum Avatar answered Apr 21 '26 00:04

Chris Gillum


I think @Chris Gillum put it well, it's hard for us to push the limits of the server to the point that things will start to scale.

Some other options available are:

  1. Use durable functions and scale with Threading: https://learn.microsoft.com/en-us/azure/azure-functions/durable-functions-cloud-backup
  2. Another method could be to use Event Hubs which are designed for massive scale. Instead of queues, have Function #1 trigger an Event, and your Function #2 subscribed to that Event Hub trigger. Adding Streaming Analytics, could also be an option to more fully expand on capabilities if needed.
like image 21
HAL9256 Avatar answered Apr 20 '26 23:04

HAL9256



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!