Skip to content

Commit e994802

Browse files
Merge pull request #233752 from ggailey777/thiago
[Functions] Target-based scaling
2 parents dff96f1 + 4a8c7df commit e994802

8 files changed

+401
-37
lines changed

articles/azure-functions/TOC.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,8 @@
299299
href: event-messaging-bindings.md
300300
- name: Event-driven scaling
301301
href: event-driven-scaling.md
302+
- name: Target-based scaling
303+
href: functions-target-based-scaling.md
302304
- name: Reliable event processing
303305
href: functions-reliable-event-processing.md
304306
- name: Concurrency
Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Event-driven scaling in Azure Functions
33
description: Explains the scaling behaviors of Consumption plan and Premium plan function apps.
4-
ms.date: 10/29/2020
4+
ms.date: 04/04/2023
55
ms.topic: conceptual
66
ms.service: azure-functions
77

@@ -10,33 +10,33 @@ ms.service: azure-functions
1010

1111
In the Consumption and Premium plans, Azure Functions scales CPU and memory resources by adding more instances of the Functions host. The number of instances is determined on the number of events that trigger a function.
1212

13-
Each instance of the Functions host in the Consumption plan is limited to 1.5 GB of memory and one CPU. An instance of the host is the entire function app, meaning all functions within a function app share resource within an instance and scale at the same time. Function apps that share the same Consumption plan scale independently. In the Premium plan, the plan size determines the available memory and CPU for all apps in that plan on that instance.
13+
Each instance of the Functions host in the Consumption plan is limited, typically to 1.5 GB of memory and one CPU. An instance of the host is the entire function app, meaning all functions within a function app share resource within an instance and scale at the same time. Function apps that share the same Consumption plan scale independently. In the Premium plan, the plan size determines the available memory and CPU for all apps in that plan on that instance.
1414

1515
Function code files are stored on Azure Files shares on the function's main storage account. When you delete the main storage account of the function app, the function code files are deleted and can't be recovered.
1616

1717
## Runtime scaling
1818

19-
Azure Functions uses a component called the *scale controller* to monitor the rate of events and determine whether to scale out or scale in. The scale controller uses heuristics for each trigger type. For example, when you're using an Azure Queue storage trigger, it scales based on the queue length and the age of the oldest queue message.
19+
Azure Functions uses a component called the *scale controller* to monitor the rate of events and determine whether to scale out or scale in. The scale controller uses heuristics for each trigger type. For example, when you're using an Azure Queue storage trigger, it uses [target-based scaling](functions-target-based-scaling.md).
2020

21-
The unit of scale for Azure Functions is the function app. When the function app is scaled out, more resources are allocated to run multiple instances of the Azure Functions host. Conversely, as compute demand is reduced, the scale controller removes function host instances. The number of instances is eventually "scaled in" to zero when no functions are running within a function app.
21+
The unit of scale for Azure Functions is the function app. When the function app is scaled out, more resources are allocated to run multiple instances of the Azure Functions host. Conversely, as compute demand is reduced, the scale controller removes function host instances. The number of instances is eventually "scaled in" when no functions are running within a function app.
2222

2323
![Scale controller monitoring events and creating instances](./media/functions-scale/central-listener.png)
2424

2525
## Cold Start
2626

27-
After your function app has been idle for a number of minutes, the platform may scale the number of instances on which your app runs down to zero. The next request has the added latency of scaling from zero to one. This latency is referred to as a _cold start_. The number of dependencies required by your function app can affect the cold start time. Cold start is more of an issue for synchronous operations, such as HTTP triggers that must return a response. If cold starts are impacting your functions, consider running in a Premium plan or in a Dedicated plan with the **Always on** setting enabled.
27+
After your function app has been idle for a number of minutes, the platform may scale the number of instances on which your app runs down to zero. The next request has the added latency of scaling from zero to one. This latency is referred to as a _cold start_. The number of dependencies required by your function app can affect the cold start time. Cold start is more of an issue for synchronous operations, such as HTTP triggers that must return a response. If cold starts are impacting your functions, consider running in a [Premium plan](functions-premium-plan.md#eliminate-cold-starts) or in a Dedicated plan with the **Always on** setting enabled.
2828

2929
## Understanding scaling behaviors
3030

31-
Scaling can vary based on several factors, and apps scale differently based on the trigger and language selected. There are a few intricacies of scaling behaviors to be aware of:
31+
Scaling can vary based on several factors, and apps scale differently based on the triggers and language selected. There are a few intricacies of scaling behaviors to be aware of:
3232

33-
* **Maximum instances:** A single function app only scales out to a maximum of 200 instances. A single instance may process more than one message or request at a time though, so there isn't a set limit on number of concurrent executions. You can [specify a lower maximum](#limit-scale-out) to throttle scale as required.
33+
* **Maximum instances:** A single function app only scales out to a [maximum allowed by the plan](functions-scale.md#scale). A single instance may process more than one message or request at a time though, so there isn't a set limit on number of concurrent executions. You can [specify a lower maximum](#limit-scale-out) to throttle scale as required.
3434
* **New instance rate:** For HTTP triggers, new instances are allocated, at most, once per second. For non-HTTP triggers, new instances are allocated, at most, once every 30 seconds. Scaling is faster when running in a [Premium plan](functions-premium-plan.md).
35-
* **Scale efficiency:** For Service Bus triggers, use _Manage_ rights on resources for the most efficient scaling. With _Listen_ rights, scaling isn't as accurate because the queue length can't be used to inform scaling decisions. To learn more about setting rights in Service Bus access policies, see [Shared Access Authorization Policy](../service-bus-messaging/service-bus-sas.md#shared-access-authorization-policies). For Event Hubs triggers, see the [this scaling guidance](#event-hubs-triggers).
35+
* **Target-based scaling:** Target-based scaling provides a fast and intuitive scaling model for customers and is currently supported for Service Bus Queues and Topics, Storage Queues, Event Hubs, and Cosmos DB extensions. Make sure to review target-based scaling to understand their scaling behavior.
3636

3737
## Limit scale-out
3838

39-
You may wish to restrict the maximum number of instances an app used to scale out. This is most common for cases where a downstream component like a database has limited throughput. By default, Consumption plan functions scale out to as many as 200 instances, and Premium plan functions will scale out to as many as 100 instances. You can specify a lower maximum for a specific app by modifying the `functionAppScaleLimit` value. The `functionAppScaleLimit` can be set to `0` or `null` for unrestricted, or a valid value between `1` and the app maximum.
39+
You may wish to restrict the maximum number of instances an app used to scale out. This is most common for cases where a downstream component like a database has limited throughput. By default, Consumption plan functions scale out to as many as 200 instances, and Premium plan functions will scale out to as many as 100 instances. You can specify a lower maximum for a specific app by modifying the `functionAppScaleLimit` value. The `functionAppScaleLimit` can be set to `0` or `null` for unrestricted, or a valid value between `1` and the app maximum.
4040

4141
```azurecli
4242
az resource update --resource-type Microsoft.Web/sites -g <RESOURCE_GROUP> -n <FUNCTION_APP-NAME>/config/web --set properties.functionAppScaleLimit=<SCALE_LIMIT>
@@ -57,27 +57,6 @@ The following considerations apply for scale-in behaviors:
5757
* For Consumption plan function apps running on Windows, only apps created after May 2021 have drain mode behaviors enabled by default.
5858
* To enable graceful shutdown for functions using the Service Bus trigger, use version 4.2.0 or a later version of the [Service Bus Extension](functions-bindings-service-bus.md).
5959

60-
## Event Hubs triggers
61-
62-
This section describes how scaling behaves when your function uses an [Event Hubs trigger](functions-bindings-event-hubs-trigger.md) or an [IoT Hub trigger](functions-bindings-event-iot-trigger.md). In these cases, each instance of an event triggered function is backed by a single [EventProcessorHost](/dotnet/api/microsoft.azure.eventhubs.processor) instance. The trigger (powered by Event Hubs) ensures that only one [EventProcessorHost](/dotnet/api/microsoft.azure.eventhubs.processor) instance can get a lease on a given partition.
63-
64-
For example, consider an event hub as follows:
65-
66-
* 10 partitions
67-
* 1,000 events distributed evenly across all partitions, with 100 messages in each partition
68-
69-
When your function is first enabled, there's only one instance of the function. Let's call the first function instance `Function_0`. The `Function_0` function has a single instance of [EventProcessorHost](/dotnet/api/microsoft.azure.eventhubs.processor) that holds a lease on all 10 partitions. This instance is reading events from partitions 0-9. From this point forward, one of the following happens:
70-
71-
* **New function instances are not needed**: `Function_0` is able to process all 1,000 events before the Functions scaling logic take effect. In this case, all 1,000 messages are processed by `Function_0`.
72-
73-
* **An additional function instance is added**: If the Functions scaling logic determines that `Function_0` has more messages than it can process, a new function app instance (`Function_1`) is created. This new function also has an associated instance of [EventProcessorHost](/dotnet/api/microsoft.azure.eventhubs.processor). As the underlying event hub detects that a new host instance is trying read messages, it load balances the partitions across the host instances. For example, partitions 0-4 may be assigned to `Function_0` and partitions 5-9 to `Function_1`.
74-
75-
* **N more function instances are added**: If the Functions scaling logic determines that both `Function_0` and `Function_1` have more messages than they can process, new `Functions_N` function app instances are created. Apps are created to the point where `N` is greater than the number of event hub partitions. In our example, Event Hubs again load balances the partitions, in this case across the instances `Function_0`...`Functions_9`.
76-
77-
As scaling occurs, `N` instances is a number greater than the number of event hub partitions. This pattern is used to ensure [EventProcessorHost](/dotnet/api/microsoft.azure.eventhubs.processor) instances are available to obtain locks on partitions as they become available from other instances. You're only charged for the resources used when the function instance executes. In other words, you aren't charged for this over-provisioning.
78-
79-
When all function execution completes (with or without errors), checkpoints are added to the associated storage account. When check-pointing succeeds, all 1,000 messages are never retrieved again.
80-
8160
## Best practices and patterns for scalable apps
8261

8362
There are many aspects of a function app that impacts how it scales, including host configuration, runtime footprint, and resource efficiency. For more information, see the [scalability section of the performance considerations article](performance-reliability.md#scalability-best-practices). You should also be aware of how connections behave as your function app scales. For more information, see [How to manage connections in Azure Functions](manage-connections.md).
@@ -97,5 +76,9 @@ Useful queries and information on how to understand your consumption bill can be
9776

9877
## Next steps
9978

79+
To learn more, see the following articles:
80+
81+
+ [Improve the performance and reliability of Azure Functions](./performance-reliability.md)
82+
+ [Azure Functions reliable event processing](./functions-reliable-event-processing.md)
10083
+ [Azure Functions hosting options](functions-scale.md)
10184

articles/azure-functions/functions-bindings-cosmosdb-v2-trigger.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Azure Cosmos DB trigger for Functions 2.x and higher
33
description: Learn to use the Azure Cosmos DB trigger in Azure Functions.
44
ms.topic: reference
5-
ms.date: 03/03/2023
5+
ms.date: 04/04/2023
66
ms.devlang: csharp, java, javascript, powershell, python
77
ms.custom: devx-track-csharp, devx-track-python, ignite-2022
88
zone_pivot_groups: programming-languages-set-functions-lang-workers
@@ -14,6 +14,8 @@ The Azure Cosmos DB Trigger uses the [Azure Cosmos DB change feed](../cosmos-db/
1414

1515
For information on setup and configuration details, see the [overview](./functions-bindings-cosmosdb-v2.md).
1616

17+
Cosmos DB scaling decisions for the Consumption and Premium plans are done via target-based scaling. For more information, see [Target-based scaling](functions-target-based-scaling.md).
18+
1719
::: zone pivot="programming-language-python"
1820
Azure Functions supports two programming models for Python. The way that you define your bindings depends on your chosen programming model.
1921

@@ -372,7 +374,7 @@ For Python v2 functions defined using a decorator, the following properties on t
372374
|-------------|-----------------------------|
373375
|`arg_name` | The variable name used in function code that represents the list of documents with changes. |
374376
|`database_name` | The name of the Azure Cosmos DB database with the collection being monitored. |
375-
|`collection_name` | The name of the Azure CosmosDB collection being monitored. |
377+
|`collection_name` | The name of the Azure Cosmos DB collection being monitored. |
376378
|`connection` | The connection string of the Azure Cosmos DB being monitored. |
377379

378380
For Python functions defined by using *function.json*, see the [Configuration](#configuration) section.

articles/azure-functions/functions-bindings-service-bus-trigger.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Azure Service Bus trigger for Azure Functions
33
description: Learn to run an Azure Function when as Azure Service Bus messages are created.
44
ms.assetid: daedacf0-6546-4355-a65c-50873e74f66b
55
ms.topic: reference
6-
ms.date: 03/06/2023
6+
ms.date: 04/04/2023
77
ms.devlang: csharp, java, javascript, powershell, python
88
ms.custom: "devx-track-csharp, devx-track-python"
99
zone_pivot_groups: programming-languages-set-functions-lang-workers
@@ -16,6 +16,8 @@ Starting with extension version 3.1.0, you can trigger on a session-enabled queu
1616

1717
For information on setup and configuration details, see the [overview](functions-bindings-service-bus.md).
1818

19+
Service Bus scaling decisions for the Consumption and Premium plans are made based on target-based scaling. For more information, see [Target-based scaling](functions-target-based-scaling.md).
20+
1921
::: zone pivot="programming-language-python"
2022
Azure Functions supports two programming models for Python. The way that you define your bindings depends on your chosen programming model.
2123

articles/azure-functions/functions-bindings-storage-queue-trigger.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Azure Queue storage trigger for Azure Functions
33
description: Learn to run an Azure Function as Azure Queue storage data changes.
44
ms.topic: reference
5-
ms.date: 02/27/2023
5+
ms.date: 04/04/2023
66
ms.devlang: csharp, java, javascript, powershell, python
77
ms.custom: "devx-track-csharp, cc996988-fb4f-47, devx-track-python"
88
zone_pivot_groups: programming-languages-set-functions-lang-workers
@@ -12,6 +12,8 @@ zone_pivot_groups: programming-languages-set-functions-lang-workers
1212

1313
The queue storage trigger runs a function as messages are added to Azure Queue storage.
1414

15+
Azure Queue storage scaling decisions for the Consumption and Premium plans are done via target-based scaling. For more information, see [Target-based scaling](functions-target-based-scaling.md).
16+
1517
::: zone pivot="programming-language-python"
1618
Azure Functions supports two programming models for Python. The way that you define your bindings depends on your chosen programming model.
1719

0 commit comments

Comments
 (0)