Do Azure Functions Actually Scale?
In my previous post, I discussed “serverless” options for deploying FastAPI applications.
The real promise of serverless or “functions as a service (FaaS)” platforms is that they automatically scale based on demand.
But, how can you verify that your FaaS is actually scaling to meet demand? And, do we see real performance gains when using a FaaS platform?
As with my previous post on MongoDB performance options, I think it’s best to verify such questions empirically. We just need a controlled experiment!
For this week’s controlled experiment, I stuck with Microsoft Azure Functions, and I stuck with the bare bones FastAPI example I introduced previously. This example has a single end point and returns fake user data via the extremely convenient mimesis fake data generator library.
I thought of adding a minimalistic database backend, but opted to keep things simple with mimesis. However, I did add a small delay to the code to simulate database access. Here’s is the API code I ended up with:
I used the set-up at: https://github.com/ecerami/fastapi_azure, and deployed to Azure as previously described.
With that, I was ready for the controlled experiment…
The first step was to configure the Dynamic Scale Out options for my function. This can be done via the Azure Portal:
I ended up doing four experiments with four different scale out limits: 1, 2, 5, and 10. With the scale out limit set to 1, you are essentially treating Azure as a single instance virtual machine. With a limit >1, you get the benefits of dynamic scaling.
At each scale out limit, I used autocannon to generate an artificial load. I specifically generated 10 concurrent requests for a total of 1K requests.
As a bonus, you can use Azure’s Application Insights to see dynamic scaling in action. This is available under Application Insights > Live Metrics. Here, for example, you can see the initial set-up with a scale out limit of 1:
For each scale out limit, I ran autocannon once to “warm” up Azure, and then gathered metrics on three runs. At each scale out limit, I also verified server scaling via Application Insights.
Here are the performance metrics I gathered:
As you can see, scale out most definitely works! At a scale out limit of 1, a thousand requests took an average of 109.29 seconds. At each subsequent scale limit, I observed faster and faster performance. And, at a scale out limit of 10, I observed an average of of 21.06 seconds!
Moral of the story: Azure scale out works most definitely works. But, best to verify everything yourself via empirical experiments!
Happy coding.