Optimize Azure Functions for Performance and Costs using Azure Load Testing
Published May 21 2024 08:30 AM 3,813 Views

Azure Functions is a serverless computing platform that allows you to run code without having to manage infrastructure, servers, or operating systems. You focus on the code that matters most to you, in the most productive language for you, and Azure Functions handles the rest. As applications grow, so do the costs and performance requirements. Finding the optimal balance between cost and performance can be challenging. In this blog post we’ll see how you can use Azure Load Testing to strike this balance.


Flex Consumption Plan

Azure Functions has launched the Flex Consumption hosting plan in preview. Flex Consumption offers a comprehensive range of scaling capabilities. It allows you to select the instance memory for your Function App. Additionally, you can also configure the concurrency per instance, which allows multiple function invocations to run concurrently on a single instance.


Cost and Performance Trade-offs

Azure Functions on the Flex Consumption plan are billed based on the memory and compute time used during execution. Higher memory settings result in faster execution times but at a higher cost per invocation. Conversely, lower memory settings reduce costs but can lead to longer execution times. This trade-off creates a dilemma for developers: how to find the optimal balance between cost and performance? Also, adjusting concurrency values can help each instance scale appropriately for the demands of the invoked functions. Identifying the optimal configuration for your Azure Functions may be manually intensive, especially if changes are made frequently.


Performance Optimizer

To help you meet your performance requirements, we recently launched a Load Testing option, that lets you easily set up a load tests against your HTTP based functions. You can now create and run load tests directly from Azure Functions (on any hosting plan), in Azure portal. Load test your functions by specifying request parameters and load configuration. You will automatically gain access to client-side and Functions metrics, which will help in identifying performance bottlenecks. You can also view the test run history to continuously monitor their web app performance.


But there's more. For Flex Consumption hosting plan, we are excited to announce the public preview of Performance Optimizer, a tool powered by Azure Load Testing, that enables you to decide the right configuration for your app by running load tests on different Functions configurations. Performance optimizer enables the following

  • In-context experience to quickly create and run tests by specifying different memory and HTTP concurrency configurations with the expected load.
  • Comparison of performance metrics from load test results across scale & concurrency configs helping you choose the right configuration.
  • Right-sizing based on performance metrics to optimize costs.

Configuring and Running Performance Optimizer

You can run the Performance optimizer on your functions with HTTP triggers. Once you have deployed your code to Azure Functions, follow the below steps to run the optimizer.

  1. Open your Function App in Azure portal.
  2. Navigate to Performance Optimizer in the Performance section of your app.Screenshot that shows Performance Optimizer in Azure FunctionsScreenshot that shows Performance Optimizer in Azure Functions
  3. If you don’t have an Azure Load Testing resource in the subscription, create one by clicking Create Load Testing resource.
  4. Now you can start by clicking on Create test profile.  A test profile describes your Function App configuration, request details and load configuration.
  5. Enter combinations of instance memory sizes and HTTP concurrency for your Function App. For each combination, a load test is run on your Function to determine the performance.Screenshot showing create test profile.Screenshot showing create test profile.


  6. Enter the HTTP request details for functions.
  7. In the Load configuration tab, select the number of engines and concurrent users per engine, load pattern and the duration of each load test.
  8. Click on Create to create and run the test profile.

When the test profile runs, the Function App configuration is modified and restarted and a load test is run. This happens for every combination of instance memory and HTTP concurrency specified in the test profile. This way you have a load test for each configuration, and you get to measure the performance of your app for each configuration under expected load.


Analyzing Results

After the Performance optimizer has completed its execution, you can view the results by examining the performance metrics. The table below shows the performance metrics for each set of configurations. You can view the response times, throughput and error rates for all the test runs. From this view, you can select the configuration that best suits your performance requirements.


In the following example, I’m testing a simple HTTP based function. I have a performance requirement criteria to a throughput of 3.5K (requests per second). As you can see below, the configuration which gives me best performance is the one with high memory and low concurrency. Four of the configuration settings meet my performance criteria. But I’m still not sure of the costs associated with this.


Group 1.png

You can use the Functions metrics for Flex Consumption to understand the costs. You can click on the detailed results for each of the load test run and view the metrics. You can also compare the load test runs as shown below. In this case, I’m comparing the OnDemandFunctionExecutionUnits metric for the test runs which meet my performance criteria.


Screenshot that shows the comparison of metricsScreenshot that shows the comparison of metrics

In the above chart, you see that [2048 MB,200] costs much less than any other configuration. You can also analyze if the additional cost is worth the improved performance for any of the configuration.

Once you’ve decided the optimal configuration, click on Apply to apply the scale and concurrency settings to your Function App.

Next steps

Using the Performance optimizer, you can right-size your Azure Functions to meet your cost and performance requirements. The results can also reduce latency, creating better experience for your end users. This exercise should be done regularly, especially if your code is released frequently.

Public preview of Performance optimizer will be available in June 2024. If you would like to get early access, please sign-up here. Meanwhile, you can create an app on Azure Functions on the Flex Consumption hosting plan.


Version history
Last update:
‎May 21 2024 02:05 AM
Updated by: