Skip to content

Commit e3f1e8d

Browse files
authored
Merge pull request #88382 from ggailey777/supportability
Consumption plan costing draft
2 parents 1033867 + db4f372 commit e3f1e8d

File tree

6 files changed

+248
-1
lines changed

6 files changed

+248
-1
lines changed

articles/azure-functions/TOC.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@
138138
href: functions-reference-node.md#typescript
139139
- name: Diagnostics
140140
href: ../app-service/overview-diagnostics.md?toc=%2fazure%2fazure-functions%2ftoc.json
141+
- name: Consumption plan costs
142+
href: functions-consumption-costs.md
141143
- name: Performance considerations
142144
href: functions-best-practices.md
143145
- name: Functions Proxies
Lines changed: 241 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,241 @@
1+
---
2+
title: Estimating Consumption plan costs in Azure Functions
3+
description: Learn how to better estimate the costs that you may incur when running your function app in a Consumption plan in Azure.
4+
author: ggailey777
5+
ms.author: glenga
6+
ms.date: 9/20/2019
7+
ms.topic: conceptual
8+
ms.service: azure-functions
9+
manager: gwallace
10+
# Customer intent: As a cloud developer, I want to understand the overall costs of running my code in Azure Functions so that I can make better architectural and business decisions.
11+
---
12+
13+
# Estimating Consumption plan costs
14+
15+
There are currently three types of hosting plans for an app that run in Azure Functions, with each plan having its own pricing model:
16+
17+
| Plan | Description |
18+
| ---- | ----------- |
19+
| [**Consumption**](functions-scale.md#consumption-plan) | You're only charged for the time that your function app runs. This plan includes a [free grant][pricing page] on a per subscription basis.|
20+
| [**Premium**](functions-scale.md#premium-plan) | Provides you with the same features and scaling mechanism as the Consumption plan, but with enhanced performance and VNET access. Cost is based on your chosen pricing tier. To learn more, see [Azure Functions Premium plan](functions-premium-plan.md). |
21+
| [**Dedicated (App Service)**](functions-scale.md#app-service-plan) <br/>(basic tier or higher) | When you need to run in dedicated VMs or in isolation, use custom images, or want to use your excess App Service plan capacity. Uses [regular App Service plan billing](https://azure.microsoft.com/pricing/details/app-service/). Cost is based on your chosen pricing tier.|
22+
23+
You chose the plan that best supports your function performance and cost requirements. To learn more, see [Azure Functions scale and hosting](functions-scale.md).
24+
25+
This article deals only with the Consumption plan, since this plan results in variable costs.
26+
27+
Durable Functions can also run in a Consumption plan. To learn more about the cost considerations when using Durable Functions, see [Durable Functions billing](./durable/durable-functions-billing.md).
28+
29+
## Consumption plan costs
30+
31+
The execution *cost* of a single function execution is measured in *GB-seconds*. Execution cost is calculated by combining its memory usage with its execution time. A function that runs for longer costs more, as does a function that consumes more memory.
32+
33+
Consider a case where the amount of memory used by the function stays constant. In this case, calculating the cost is simple multiplication. For example, say that your function consumed 0.5 GB for 3 seconds. Then the execution cost is `0.5GB * 3s = 1.5 GB-seconds`.
34+
35+
Since memory usage changes over time, the calculation is essentially the integral of memory usage over time. The system does this calculation by sampling the memory usage of the process (along with child processes) at regular intervals. As mentioned on the [pricing page], memory usage is rounded up to the nearest 128-MB bucket. When your process is using 160 MB, you're charged for 256 MB. The calculation takes into account concurrency, which is multiple concurrent function executions in the same process.
36+
37+
> [!NOTE]
38+
> While CPU usage isn't directly considered in execution cost, it can have an impact on the cost when it affects the execution time of the function.
39+
40+
## Other related costs
41+
42+
When estimating the overall cost of running your functions in any plan, remember that the Functions runtime uses several other Azure services, which are each billed separately. When calculating pricing for function apps, any triggers and bindings you have that integrate with other Azure services require you to create and pay for those additional services.
43+
44+
For functions running in a Consumption plan, the total cost is the execution cost of your functions, plus the cost of bandwidth and additional services.
45+
46+
When estimating the overall costs of your function app and related services, use the [Azure pricing calculator](https://azure.microsoft.com/pricing/calculator/?service=functions).
47+
48+
| Related cost | Description |
49+
| ------------ | ----------- |
50+
| **Storage account** | Each function app requires that you have an associated General Purpose [Azure Storage account](../storage/common/storage-introduction.md#types-of-storage-accounts), which is [billed separately](https://azure.microsoft.com/pricing/details/storage/). This account is used internally by the Functions runtime, but you can also use it for Storage triggers and bindings. If you don't have a storage account, one is created for you when the function app is created. To learn more, see [Storage account requirements](functions-scale.md#storage-account-requirements).|
51+
| **Application Insights** | Functions relies on [Application Insights](../azure-monitor/app/app-insights-overview.md) to provide a high-performance monitoring experience for your function apps. While not required, you should [enable Application Insights integration](functions-monitoring.md#enable-application-insights-integration). A free grant of telemetry data is included every month. To learn more, see [the Azure Monitor pricing page](https://azure.microsoft.com/pricing/details/monitor/). |
52+
| **Network bandwidth** | You don't pay for data transfer between Azure services in the same region. However, you can incur costs for outbound data transfers to another region or outside of Azure. To learn more, see [Bandwidth pricing details](https://azure.microsoft.com/pricing/details/bandwidth/). |
53+
54+
## Behaviors affecting execution time
55+
56+
The following behaviors of your functions can impact the execution time:
57+
58+
+ **Triggers and bindings**: The time taken to read input from and write output to your [function bindings](functions-triggers-bindings.md) is counted as execution time. For example, when your function uses an output binding to write a message to an Azure storage queue, your execution time includes the time taken to write the message to the queue, which is included in the calculation of the function cost.
59+
60+
+ **Asynchronous execution**: The time that your function waits for the results of an async request (`await` in C#) is counted as execution time. The GB-second calculation is based on the start and end time of the function and the memory usage over that period. What is happening over that time in terms of CPU activity isn't factored into the calculation. You may be able to reduce costs during asynchronous operations by using [Durable Functions](durable/durable-functions-overview.md). You're not billed for time spent at awaits in orchestrator functions.
61+
62+
## View execution data
63+
64+
In [your invoice](/billing/billing-download-azure-invoice.md), you can view the cost-related data of **Total Executions - Functions** and **Execution Time - Functions**, along with the actual billed costs. However, this invoice data is a monthly aggregate for a past invoice period.
65+
66+
To better understand the cost impact of your functions, you can use Azure Monitor to view cost-related metrics currently being generated by your function apps. You can use either [Azure Monitor metrics explorer](../azure-monitor/platform/metrics-getting-started.md) in the [Azure portal] or REST APIs to get this data.
67+
68+
### Monitor metrics explorer
69+
70+
Use [Azure Monitor metrics explorer](../azure-monitor/platform/metrics-getting-started.md) to view cost-related data for your Consumption plan function apps in a graphical format.
71+
72+
1. At the top of the [Azure portal] in **Search services, resources, and docs** search for `monitor` and select **Monitor** under **Services**.
73+
74+
1. At the left, select **Metrics** > **Select a resource**, then use the settings below the image to choose your function app.
75+
76+
![Select your function app resource](media/functions-consumption-costing/select-a-resource.png)
77+
78+
79+
|Setting |Suggested value |Description |
80+
|---------|---------|---------|
81+
| Subscription | Your subscription | The subscription with your function app. |
82+
| Resource group | Your resource group | The resource group that contains your function app. |
83+
| Resource type | App Services | Function apps are shown as App Services instances in Monitor. |
84+
| Resource | Your function app | The function app to monitor. |
85+
86+
1. Select **Apply** to choose your function app as the resource to monitor.
87+
88+
1. From **Metric**, choose **Function execution count** and **Sum** for **Aggregation**. This adds the sum of the execution counts during chosen period to the chart.
89+
90+
![Define a functions app metric to add to the chart](media/functions-consumption-costing/monitor-metrics-add-metric.png)
91+
92+
1. Select **Add metric** and repeat steps 2-4 to add **Function execution units** to the chart.
93+
94+
The resulting chart contains the totals for both execution metrics in the chosen time range, which in this case is two hours.
95+
96+
![Graph of function execution counts and execution units](media/functions-consumption-costing/monitor-metrics-execution-sum.png)
97+
98+
As the number of execution units is so much greater than the execution count, the chart just shows execution units.
99+
100+
This chart shows a total of 1.11 billion `Function Execution Units` consumed in a two-hour period, measured in MB-milliseconds. To convert to GB-seconds, divide by 1024000. In this example, the function app consumed `1110000000 / 1024000 = 1083.98` GB-seconds. You can take this value and multiply by the current price of execution time on the [Functions pricing page][pricing page], which gives you the cost of these two hours, assuming you've already used any free grants of execution time.
101+
102+
### Azure CLI
103+
104+
The [Azure CLI](/cli/azure/) has commands for retrieving metrics. You can use the CLI from a local command environment or directly from the portal using [Azure Cloud Shell](../cloud-shell/overview.md). For example, the following [az monitor metrics list](/cli/azure/monitor/metrics#az-monitor-metrics-list) command returns hourly data over same time period used before.
105+
106+
Make sure to replace `<AZURE_SUBSCRIPTON_ID>` with your Azure subscription ID running the command.
107+
108+
```azurecli-interactive
109+
az monitor metrics list --resource /subscriptions/<AZURE_SUBSCRIPTION_ID>/resourceGroups/metrics-testing-consumption/providers/Microsoft.Web/sites/metrics-testing-consumption --metric FunctionExecutionUnits,FunctionExecutionCount --aggregation Total --interval PT1H --start-time 2019-09-11T21:46:00Z --end-time 2019-09-11T23:18:00Z
110+
```
111+
112+
This command returns a JSON payload that looks like the following example:
113+
114+
```json
115+
{
116+
"cost": 0.0,
117+
"interval": "1:00:00",
118+
"namespace": "Microsoft.Web/sites",
119+
"resourceregion": "centralus",
120+
"timespan": "2019-09-11T21:46:00Z/2019-09-11T23:18:00Z",
121+
"value": [
122+
{
123+
"id": "/subscriptions/XXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX/resourceGroups/metrics-testing-consumption/providers/Microsoft.Web/sites/metrics-testing-consumption/providers/Microsoft.Insights/metrics/FunctionExecutionUnits",
124+
"name": {
125+
"localizedValue": "Function Execution Units",
126+
"value": "FunctionExecutionUnits"
127+
},
128+
"resourceGroup": "metrics-testing-consumption",
129+
"timeseries": [
130+
{
131+
"data": [
132+
{
133+
"average": null,
134+
"count": null,
135+
"maximum": null,
136+
"minimum": null,
137+
"timeStamp": "2019-09-11T21:46:00+00:00",
138+
"total": 793294592.0
139+
},
140+
{
141+
"average": null,
142+
"count": null,
143+
"maximum": null,
144+
"minimum": null,
145+
"timeStamp": "2019-09-11T22:46:00+00:00",
146+
"total": 316576256.0
147+
}
148+
],
149+
"metadatavalues": []
150+
}
151+
],
152+
"type": "Microsoft.Insights/metrics",
153+
"unit": "Count"
154+
},
155+
{
156+
"id": "/subscriptions/XXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX/resourceGroups/metrics-testing-consumption/providers/Microsoft.Web/sites/metrics-testing-consumption/providers/Microsoft.Insights/metrics/FunctionExecutionCount",
157+
"name": {
158+
"localizedValue": "Function Execution Count",
159+
"value": "FunctionExecutionCount"
160+
},
161+
"resourceGroup": "metrics-testing-consumption",
162+
"timeseries": [
163+
{
164+
"data": [
165+
{
166+
"average": null,
167+
"count": null,
168+
"maximum": null,
169+
"minimum": null,
170+
"timeStamp": "2019-09-11T21:46:00+00:00",
171+
"total": 33538.0
172+
},
173+
{
174+
"average": null,
175+
"count": null,
176+
"maximum": null,
177+
"minimum": null,
178+
"timeStamp": "2019-09-11T22:46:00+00:00",
179+
"total": 13040.0
180+
}
181+
],
182+
"metadatavalues": []
183+
}
184+
],
185+
"type": "Microsoft.Insights/metrics",
186+
"unit": "Count"
187+
}
188+
]
189+
}
190+
```
191+
This particular response shows that from `2019-09-11T21:46` to `2019-09-11T23:18`, during which the app consumed 1110000000 MB-milliseconds (1083.98 GB-seconds).
192+
193+
## Determine memory usage
194+
195+
Function execution units are a combination of execution time and your memory usage, which makes it a difficult metric for understanding memory usage. Memory data isn't a metric currently available through Azure Monitor. However, if you want to optimize the memory usage of your app, can use the performance counter data collected by Application Insights.
196+
197+
If you haven't already done so, [enable Application Insights in your function app](functions-monitoring.md#enable-application-insights-integration). With this integration enabled, you can [query this telemetry data in the portal](functions-monitoring.md#query-telemetry-data).
198+
199+
Under **Monitoring**, select **Logs (Analytics)**, then copy the following telemetry query and paste it into the query window and select **Run**. This query returns the total memory usage at each sampled time.
200+
201+
```
202+
performanceCounters
203+
| where name == "Private Bytes"
204+
| project timestamp, name, value
205+
```
206+
207+
The results look like the following example:
208+
209+
| timestamp \[UTC\] | name | value |
210+
|----------------------------|---------------|-------------|
211+
| 9/12/2019, 1:05:14\.947 AM | Private Bytes | 209,932,288 |
212+
| 9/12/2019, 1:06:14\.994 AM | Private Bytes | 212,189,184 |
213+
| 9/12/2019, 1:06:30\.010 AM | Private Bytes | 231,714,816 |
214+
| 9/12/2019, 1:07:15\.040 AM | Private Bytes | 210,591,744 |
215+
| 9/12/2019, 1:12:16\.285 AM | Private Bytes | 216,285,184 |
216+
| 9/12/2019, 1:12:31\.376 AM | Private Bytes | 235,806,720 |
217+
218+
## Function-level metrics
219+
220+
Azure Monitor tracks metrics at the resource level, which for Functions is the function app. Application Insights integration emits metrics on a per-function basis. Here's an example analytics query to get the average duration of a function:
221+
222+
```
223+
customMetrics
224+
| where name contains "Duration"
225+
| extend averageDuration = valueSum / valueCount
226+
| summarize averageDurationMilliseconds=avg(averageDuration) by name
227+
```
228+
229+
| name | averageDurationMilliseconds |
230+
|----------------------------|-----------------------------|
231+
| QueueTrigger AvgDurationMs | 16\.087 |
232+
| QueueTrigger MaxDurationMs | 90\.249 |
233+
| QueueTrigger MinDurationMs | 8\.522 |
234+
235+
## Next steps
236+
237+
> [!div class="nextstepaction"]
238+
> [Learn more about Monitoring function apps](functions-monitoring.md)
239+
240+
[pricing page]:https://azure.microsoft.com/pricing/details/functions/
241+
[Azure portal]: https://portal.azure.com

articles/azure-functions/functions-scale.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ The Consumption plan is the default hosting plan and offers the following benefi
5959

6060
Function apps in the same region can be assigned to the same Consumption plan. There's no downside or impact to having multiple apps running in the same Consumption plan. Assigning multiple apps to the same consumption plan has no impact on resilience, scalability, or reliability of each app.
6161

62+
To learn more about how to estimate costs when running in a Consumption plan, see [Understanding Consumption plan costs](functions-consumption-costs.md).
63+
6264
## <a name="premium-plan"></a>Premium plan (preview)
6365

6466
When you're using the Premium plan, instances of the Azure Functions host are added and removed based on the number of incoming events just like the Consumption plan. Premium plan supports the following features:
@@ -125,7 +127,9 @@ When the output from this command is `dynamic`, your function app is in the Cons
125127

126128
## Storage account requirements
127129

128-
On any plan, a function app requires a general Azure Storage account, which supports Azure Blob, Queue, Files, and Table storage. This is because Functions rely on Azure Storage for operations such as managing triggers and logging function executions, but some storage accounts do not support queues and tables. These accounts, which include blob-only storage accounts (including premium storage) and general-purpose storage accounts with zone-redundant storage replication, are filtered-out from your existing **Storage Account** selections when you create a function app.
130+
On any plan, a function app requires a general Azure Storage account, which supports Azure Blob, Queue, Files, and Table storage. This is because Functions relies on Azure Storage for operations such as managing triggers and logging function executions, but some storage accounts do not support queues and tables. These accounts, which include blob-only storage accounts (including premium storage) and general-purpose storage accounts with zone-redundant storage replication, are filtered-out from your existing **Storage Account** selections when you create a function app.
131+
132+
The same storage account used by your function app can also be used by your triggers and bindings to store your application data. However, for storage-intensive operations, you should use a separate storage account.
129133

130134
<!-- JH: Does using a Premium Storage account improve perf? -->
131135

55.7 KB
Loading
138 KB
Loading
115 KB
Loading

0 commit comments

Comments
 (0)