Skip to content

Commit 86b232d

Browse files
authored
Merge pull request #227545 from lilyjma/DFBestPractice
Durable Functions best practice reference
2 parents f0188d1 + 5c3d414 commit 86b232d

17 files changed

+266
-0
lines changed

articles/azure-functions/durable/TOC.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@
136136
items:
137137
- name: Develop
138138
items:
139+
- name: Durable Functions best practices and diagnostic tools
140+
href: durable-functions-best-practice-reference.md
141+
- name: Durable Functions Rosyln Analyzer (C# only)
142+
href: durable-functions-roslyn-analyzer.md
139143
- name: Create in Azure portal
140144
href: durable-functions-create-portal.md
141145
- name: Manage connections
@@ -162,8 +166,14 @@
162166
href: durable-functions-diagnostics.md
163167
- name: Monitoring
164168
href: ../functions-monitoring.md?toc=/azure/azure-functions/durable/toc.json
169+
- name: App diagnostics in Azure portal
170+
href: function-app-diagnostics.md
165171
- name: Pricing
166172
href: durable-functions-billing.md
173+
- name: Debug
174+
items:
175+
- name: Upgrade Durable Functions extension version
176+
href: durable-functions-extension-upgrade.md
167177
- name: Resources
168178
items:
169179
- name: Build your skills with Microsoft Learn training
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
---
2+
title: Durable Functions best practices and diagnostic tools
3+
description: Learn about the best practices when using Durable Functions and the various tools available for diagnosing problems.
4+
author: lilyjma
5+
ms.topic: conceptual
6+
ms.date: 02/15/2023
7+
ms.author: azfuncdf
8+
---
9+
10+
# Durable Functions best practices and diagnostic tools
11+
12+
This article details some best practices when using Durable Functions. It also describes various tools to help diagnose problems during development, testing, and production use.
13+
14+
## Best practices
15+
16+
### Use the latest version of the Durable Functions extension and SDK
17+
18+
There are two components that a function app uses to execute Durable Functions. One is the *Durable Functions SDK* that allows you to write orchestrator, activity, and entity functions using your target programming language. The other is the *Durable extension*, which is the runtime component that actually executes the code. With the exception of .NET in-process apps, the SDK and the extension are versioned independently.
19+
20+
Staying up to date with the latest extension and SDK ensures your application benefits from the latest performance improvements, features, and bug fixes. Upgrading to the latest versions also ensures that Microsoft can collect the latest diagnostic telemetry to help accelerate the investigation process when you open a support case with Azure.
21+
22+
* See [Upgrade durable functions extension version](durable-functions-extension-upgrade.md) for instructions on getting the latest extension version.
23+
* To ensure you're using the latest version of the SDK, check the package manager of the language you're using.
24+
25+
### Adhere to Durable Functions [code constraints](durable-functions-code-constraints.md)
26+
27+
The [replay](durable-functions-orchestrations.md#reliability) behavior of orchestrator code creates constraints on the type of code that you can write in an orchestrator function. An example of a constraint is that your orchestrator function must use deterministic APIs so that each time it’s replayed, it produces the same result.
28+
29+
> [!NOTE]
30+
> The Durable Functions Roslyn Analyzer is a live code analyzer that guides C# users to adhere to Durable Functions specific code constraints. See [Durable Functions Roslyn Analyzer](durable-functions-roslyn-analyzer.md) for instructions on how to enable it on Visual Studio and Visual Studio Code.
31+
32+
### Familiarize yourself with your programming language's Azure Functions performance settings
33+
34+
_Using default settings_, the language runtime you select may impose strict concurrency restrictions on your functions. For example: only allowing 1 function to execute at a time on a given VM. These restrictions can usually be relaxed by _fine tuning_ the concurrency and performance settings of your language. If you're looking to optimize the performance of your Durable Functions application, you will need to familiarize yourself with these settings.
35+
36+
Below is a non-exhaustive list of some of the languages that often benefit from fine tuning their performance and concurrency settings, and their guidelines for doing so.
37+
38+
* [JavaScript](../functions-reference-node.md#scaling-and-concurrency)
39+
* [PowerShell](../functions-reference-powershell.md#concurrency)
40+
* [Python](../python-scale-performance-reference.md)
41+
42+
### Guarantee unique Task Hub names per app
43+
44+
Multiple Durable Function apps can share the same storage account. By default, the name of the app is used as the task hub name, which ensures that accidental sharing of task hubs won't happen. If you need to explicitly configure task hub names for your apps in host.json, you must ensure that the names are [*unique*](durable-functions-task-hubs.md#multiple-function-apps). Otherwise, the multiple apps will compete for messages, which could result in undefined behavior, including orchestrations getting unexpectedly "stuck" in the Pending or Running state.
45+
46+
The only exception is if you deploy *copies* of the same app in [multiple regions](durable-functions-disaster-recovery-geo-distribution.md); in this case, you can use the same task hub for the copies.
47+
48+
### Follow guidance when deploying code changes to running orchestrators
49+
50+
It's inevitable that functions will be added, removed, and changed over the lifetime of an application. Examples of [common breaking changes](durable-functions-versioning.md) include changing activity or entity function signatures and changing orchestrator logic. These changes are a problem when they affect orchestrations that are still running. If deployed incorrectly, code changes could lead to orchestrations failing with a non-deterministic error, getting stuck indefinitely, performance degradation, etc. Refer to recommended [mitigation strategies](durable-functions-versioning.md#mitigation-strategies) when making code changes that may impact running orchestrations.
51+
52+
### Keep function inputs and outputs as small as possible
53+
54+
You can run into memory issues if you provide large inputs and outputs to and from Durable Functions APIs.
55+
56+
Inputs and outputs to Durable Functions APIs are serialized into the orchestration history. This means that large inputs and outputs can, over time, greatly contribute to an orchestrator history growing unbounded, which risks causing memory exceptions during [replay](durable-functions-orchestrations.md#reliability).
57+
58+
To mitigate the impact of large inputs and outputs to APIs, you may choose to delegate some work to sub-orchestrators. This helps load balance the history memory burden from a single orchestrator to multiple ones, therefore keeping the memory footprint of individual histories small.
59+
60+
That said the best practice for dealing with _large_ data is to keep it in external storage and to only materialize that data inside Activities, when needed. When taking this approach, instead of communicating the data itself as inputs and/or outputs of Durable Functions APIs, you can pass in some lightweight identifier that allows you to retrieve that data from external storage when needed in your Activities.
61+
62+
### Fine tune your Durable Functions concurrency settings
63+
64+
A single worker instance can execute multiple work items concurrently to increase efficiency. However, processing too many work items concurrently risks exhausting resources like CPU capacity, network connections, etc. In many cases, this shouldn’t be a concern because scaling and limiting work items are handled automatically for you. That said, if you’re experiencing performance issues (such as orchestrators taking too long to finish, are stuck in pending, etc.) or are doing performance testing, you could [configure concurrency limits](durable-functions-perf-and-scale.md#configuration-of-throttles) in the host.json file.
65+
66+
> [!NOTE]
67+
> This is not a replacement for fine-tuning the performance and concurrency settings of your language runtime in Azure Functions. The Durable Functions concurrency settings only determine how much work can be assigned to a given VM at a time, but it does not determine the degree of parallelism in processing that work inside the VM. The latter requires fine-tuning the language runtime performance settings.
68+
69+
70+
## Diagnostic tools
71+
72+
There are several tools available to help you diagnose problems.
73+
74+
### Durable Functions and Durable Task Framework Logs
75+
76+
#### Durable Functions Extension
77+
The Durable extension emits tracking events that allow you to trace the end-to-end execution of an orchestration. These tracking events can be found and queried using the [Application Insights Analytics](../../azure-monitor/logs/log-query-overview.md) tool in the Azure portal. The verbosity of tracking data emitted can be configured in the `logger` (Functions 1.x) or `logging` (Functions 2.0) section of the host.json file. See [configuration details](durable-functions-diagnostics.md#functions-10).
78+
79+
#### Durable Task Framework
80+
Starting in v2.3.0 of the Durable extension, logs emitted by the underlying Durable Task Framework (DTFx) are also available for collection. See [details on how to enable these logs](durable-functions-diagnostics.md#durable-task-framework-logging).
81+
82+
### Azure portal
83+
84+
#### Diagnose and solve problems
85+
Azure Function App Diagnostics is a useful resource on Azure portal for monitoring and diagnosing potential issues in your application. It also provides suggestions to help resolve problems based on the diagnosis. See [Azure Function App Diagnostics](function-app-diagnostics.md).
86+
87+
#### Durable Functions Orchestration traces
88+
Azure portal provides orchestration trace details to help you understand the status of each orchestration instance and trace the end-to-end execution. When you look at the list of functions inside your Azure Functions app, you'll see a **Monitor** column that contains links to the traces. You need to have Applications Insights enabled for your app to get this information.
89+
90+
### Durable Functions Monitor Extension
91+
92+
This is a [Visual Studio Code extension](https://github.com/microsoft/DurableFunctionsMonitor) that provides a UI for monitoring, managing, and debugging your orchestration instances.
93+
94+
### Roslyn Analyzer
95+
96+
The Durable Functions Roslyn Analyzer is a live code analyzer that guides C# users to adhere to Durable Functions specific [code constraints](durable-functions-code-constraints.md). See [Durable Functions Roslyn Analyzer](durable-functions-roslyn-analyzer.md) for instructions on how to enable it on Visual Studio and Visual Studio Code.
97+
98+
99+
## Support
100+
101+
For questions and support, you may open an issue in one of the GitHub repos below. When reporting a bug in Azure, including information such as affected instance IDs, time ranges in UTC showing the problem, the application name (if possible) and deployment region will greatly speed up investigations.
102+
- [Durable Functions extension and .NET in-process SDK](https://github.com/Azure/azure-functions-durable-extension/issues)
103+
- [.NET isolated SDK](https://github.com/microsoft/durabletask-dotnet/issues)
104+
- [Durable Functions for Java](https://github.com/microsoft/durabletask-java/issues)
105+
- [Durable Functions for JavaScript](https://github.com/Azure/azure-functions-durable-js/issues)
106+
- [Durable Functions for Python](https://github.com/Azure/azure-functions-durable-python/issues)
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
---
2+
title: Upgrade Durable Functions extension version
3+
description: Learn why it's important to use the latest version of the Durable Functions extension and how to upgrade to the latest.
4+
author: lilyjma
5+
ms.topic: conceptual
6+
ms.date: 02/15/2023
7+
ms.author: azfuncdf
8+
---
9+
10+
# Upgrade Durable Functions extension version
11+
12+
13+
Many issues users experience with Durable Functions can be resolved simply by upgrading to the latest version of the extension, which often contains important bug fixes and performance improvements. You can follow the instructions in this article to get the latest version of the Durable Functions extension.
14+
15+
Changes to the extension can be found in the [Release page](https://github.com/Azure/azure-functions-durable-extension/releases) of the `Azure/azure-functions-durable-extension` repo. You can also configure to receive notifications whenever there's a new extension release by going to the **Releases page**, clicking on **Watch**, then on **Custom**, and finally selecting the **Releases** filter:
16+
17+
:::image type="content" source="media/durable-functions-best-practice/watch-releases-1.png" alt-text="Screenshot of step 1 to set up release notifications.":::
18+
19+
:::image type="content" source="media/durable-functions-best-practice/watch-releases-2.png" alt-text="Screenshot of step 2 to set up release notifications.":::
20+
21+
## Reference the latest NuGet packages (.NET apps only)
22+
.NET apps can get the latest version of the Durable Functions extension by referencing the latest NuGet package:
23+
24+
* [.NET in-process worker](https://www.nuget.org/packages/Microsoft.Azure.WebJobs.Extensions.DurableTask)
25+
* [.NET isolated worker](https://www.nuget.org/packages/Microsoft.Azure.Functions.Worker.Extensions.DurableTask)
26+
27+
If you're using the Netherite or MSSQL [storage providers](durable-functions-storage-providers.md) (instead of Azure Storage), you need to reference one of the following:
28+
29+
* [Netherite, in-process worker](https://www.nuget.org/packages/Microsoft.Azure.DurableTask.Netherite.AzureFunctions)
30+
* [Netherite, isolated worker](https://www.nuget.org/packages/Microsoft.Azure.Functions.Worker.Extensions.DurableTask.Netherite)
31+
* [MSSQL, in-process worker](https://www.nuget.org/packages/Microsoft.DurableTask.SqlServer.AzureFunctions)
32+
* [MSSQL, isolated worker](https://www.nuget.org/packages/Microsoft.Azure.Functions.Worker.Extensions.DurableTask.SqlServer)
33+
34+
## Upgrade the extension bundle
35+
[Extension bundles](../functions-bindings-register.md#extension-bundles) provide an easy and convenient way for non-.NET function apps to reference and use various Azure Function triggers and bindings. For example, if you need to send a message to Event Hubs every time your function is triggered, you can use the Event Hubs extension to gain access to Event Hubs bindings. The Durable Functions extension is also included in each version of extension bundles. Extension bundles are automatically configured in host.json when creating a function app using any of the supported development tools.
36+
37+
Most non-.NET applications rely on extension bundles to gain access to various triggers and bindings. The [latest bundle release](https://github.com/Azure/azure-functions-extension-bundles) often contains the latest version of the Durable Functions extension with critical bug fixes and performance improvements. Therefore, it's important that your app uses the latest version of extension bundles. You can check your host.json file to see whether the version range you're using includes the latest extension bundle version.
38+
39+
## Manually upgrade the Durable Functions extension
40+
If upgrading the extension bundle didn't resolve your problem, and you noticed a newer release of the Durable Functions extension containing a potential fix to your problem, then you could try to manually upgrade the extension itself. Note that this is only intended for advanced scenarios or when time-sensitive fixes are necessary as there are many drawbacks to manually managing extensions. For example, you may have to deal to .NET errors when the extensions you use are incompatible with each other. You also need to manually upgrade extensions to get the latest fixes and patches instead of getting them automatically through the extension bundle.
41+
42+
First, remove the `extensionBundle` section from your host.json file.
43+
44+
Install the `dotnet` CLI if you don't already have it. You can get it from this [page](https://www.microsoft.com/net/download/).
45+
46+
Because applications normally use more than one extension, it's recommended that you run the following to manually install all the latest version of all extensions supported by Extension Bundles:
47+
48+
```console
49+
func extensions install
50+
```
51+
52+
However, if you **only** wish to install the latest Durable Functions extension release, you would run the following command:
53+
54+
```console
55+
func extensions install Microsoft.Azure.WebJobs.Extensions.DurableTask -v <version>
56+
```
57+
58+
For example:
59+
60+
```console
61+
func extensions install Microsoft.Azure.WebJobs.Extensions.DurableTask -v 2.9.1
62+
```
63+
64+
65+
66+
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
title: Durable Functions Roslyn Analyzer (C# only)
3+
description: Learn about how to use the Roslyn Analyzer to help adhere to Durable Functions specific code constraints.
4+
author: amdeel
5+
ms.topic: conceptual
6+
ms.date: 02/15/2023
7+
ms.author: azfuncdf
8+
---
9+
10+
# Durable Functions Rosyln Analyzer (C# only)
11+
12+
The Durable Functions Roslyn Analyzer is a live code analyzer that guides C# users to adhere to Durable Functions specific [code constraints](./durable-functions-code-constraints.md). This analyzer is enabled by default to check your Durable Functions code and generate warnings and errors when there's any. Currently, the analyzer is only supported in the .NET in-process worker.
13+
14+
For more detailed information on the analyzer (improvements, releases, bug fixes, etc.), see its [release notes page](https://github.com/Azure/azure-functions-durable-extension/releases/tag/Analyzer-v0.2.0).
15+
16+
17+
## Configuration
18+
19+
### Visual Studio
20+
21+
For the best experience, you'll want to enable full solution analysis in your Visual Studio settings. This can be done by going to **Tools** -> **Options** -> **Text Editor** -> **C#** -> **Advanced** -> **"Entire solution"**:
22+
23+
:::image type="content" source="media/durable-functions-best-practice/roslyn-analyzer-1.png" alt-text="Screenshot of configuring Roslyn Analyzer in Visual Studio.":::
24+
25+
Depending on the version of Visual Studio, you may also see "Enable full solution analysis":
26+
27+
:::image type="content" source="media/durable-functions-best-practice/roslyn-analyzer-2.png" alt-text="Screenshot of configuring Roslyn Analyzer in another version of Visual Studio.":::
28+
29+
To disable the analyzer, refer to these [instructions](/visualstudio/code-quality/in-source-suppression-overview).
30+
31+
### Visual Studio Code
32+
33+
Open **Settings** by clicking the wheel icon on the lower left corner, then search for “rosyln”. “Enable Rosyln Analyzers” should show up as one of the results. Check the enable support box.
34+
35+
:::image type="content" source="media/durable-functions-best-practice/roslyn-analyzer-vs-code.png" alt-text="Screenshot of configuring Roslyn Analyzer in Visual Studio Code.":::

0 commit comments

Comments
 (0)