|
1 | 1 | ---
|
2 |
| -title: Scale Dapr components with KEDA scalers for Azure Container Apps |
| 2 | +title: Scale Dapr applications with KEDA scalers |
3 | 3 | description: Learn how to use KEDA scalers to scale an Azure Container App and its Dapr sidecar.
|
4 | 4 | author: hhunter-ms
|
5 | 5 | ms.author: hannahhunter
|
6 | 6 | ms.service: container-apps
|
7 |
| -ms.topic: how-to |
8 |
| -ms.date: 04/10/2023 |
| 7 | +ms.topic: conceptual |
| 8 | +ms.date: 04/11/2023 |
9 | 9 | ---
|
10 | 10 |
|
11 |
| -# Scale Dapr components with KEDA scalers for Azure Container Apps |
| 11 | +# Scale Dapr applications with KEDA scalers |
12 | 12 |
|
13 |
| -When scale rules are omitted on an Azure Container Apps resource, the container app is created with a default scale rule. If the resource receives no incoming traffic over a duration of five minutes, that default rule scales all replicas down to zero. This behavior can be problematic and unexpected when applying Dapr components, specifically pub/sub subscriptions and input bindings. |
| 13 | +Using [KEDA scalers](https://keda.sh/), you can scale your application and its [Dapr](https://docs.dapr.io/) sidecar when it has scaled to zero with inbound events and messages. In this guide, we demonstrate scaling a Dapr pub/sub application by setting up a KEDA scaler to watch for messages coming into the queue and triggers the Dapr sidecar to spin up. |
14 | 14 |
|
15 |
| -Using KEDA scalers, you can scale your application and its Dapr sidecar when it has scaled to zero with inbound events and messages. However, configuring _both_ a Dapr component and a corresponding KEDA scaler isn't intuitive. |
16 |
| - |
17 |
| -todo: solution - if it's redundant or complex, then why? |
18 |
| - |
19 |
| -## Configure container apps for scaling |
20 |
| - |
21 |
| -In this scenario: |
22 |
| -1. In a loop, a `checkout` publisher container app continuously publishes messages via the Dapr pub/sub API to the `orders` topic in Azure Service Bus. |
| 15 | +In the following scenario, we examine the Bicep for: |
| 16 | +1. A `checkout` publisher container app continuously publishes messages via the Dapr pub/sub API to the `orders` topic in Azure Service Bus. |
| 17 | +1. The Dapr Azure Service Bus component |
23 | 18 | 1. An `order-processor` subscriber container app subscribed to the `orders` topic receives and processes messages as they arrive.
|
24 | 19 |
|
25 |
| -Let’s look at the Bicep for: |
26 |
| -- The `checkout` and `order-processor` container apps |
27 |
| -- The Dapr Azure Service Bus component |
28 |
| - |
29 |
| -todo: need actual steps - so far it's more of a scenario concept, user isn't walking through any steps. |
| 20 | +## Publisher container app |
30 | 21 |
|
31 |
| -### Publisher container app |
| 22 | +The `checkout` publisher is a headless service that runs indefinitely and never scales down to zero. |
32 | 23 |
|
33 |
| -The `checkout` publisher is a headless service that you want to run indefinitely and never scale down to zero. |
34 |
| - |
35 |
| -Set the `minReplicas` to "1", which ensures the container app doesn't follow the default behavior. |
| 24 | +We do this by setting the `minReplicas` to "1", which ensures the container app doesn't follow the default behavior. |
36 | 25 |
|
37 | 26 | ```bicep
|
38 | 27 | resource checkout 'Microsoft.App/containerApps@2022-03-01' = {
|
@@ -90,9 +79,9 @@ resource checkout 'Microsoft.App/containerApps@2022-03-01' = {
|
90 | 79 | }
|
91 | 80 | ```
|
92 | 81 |
|
93 |
| -### Dapr component |
| 82 | +## Dapr Azure Service Bus component |
94 | 83 |
|
95 |
| -Next, configure the Dapr component for connecting to Azure Service Bus via a connection string. |
| 84 | +Next, take a look at the Dapr component for connecting to Azure Service Bus via a connection string. |
96 | 85 |
|
97 | 86 | ```bicep
|
98 | 87 | resource daprComponent 'daprComponents' = {
|
@@ -121,9 +110,9 @@ resource daprComponent 'daprComponents' = {
|
121 | 110 | }
|
122 | 111 | ```
|
123 | 112 |
|
124 |
| -### Subscriber container app |
| 113 | +## Subscriber container app |
125 | 114 |
|
126 |
| -In the `order-processor` subscriber, add a custom scale rule on the resource for the type `azure-servicebus`. With this scale rule, KEDA can scale up the container app and its Dapr sidecar, allowing incoming messages to be processed again while order-processor is scaled to zero. |
| 115 | +In the `order-processor` subscriber, we've added a custom scale rule on the resource for the type `azure-servicebus`. With this scale rule, KEDA can scale up the container app and its Dapr sidecar, allowing incoming messages to be processed while `order-processor` is scaled to zero. |
127 | 116 |
|
128 | 117 | ```bicep
|
129 | 118 | resource orders 'Microsoft.App/containerApps@2022-03-01' = {
|
@@ -214,6 +203,21 @@ resource orders 'Microsoft.App/containerApps@2022-03-01' = {
|
214 | 203 | }
|
215 | 204 | ```
|
216 | 205 |
|
| 206 | +## What happened? |
| 207 | + |
| 208 | +By default, [Container Apps assigns an http-based scale rule to applications](./scale-app.md), scaling apps based on the number of incoming http requests. However, since the `order-processor` application is using the Dapr pub/sub abstraction to pull messages from a queue, it needs to define a custom scaler based on the number of messages waiting to be processed. |
| 209 | + |
| 210 | +Behind the scenes, KEDA scales our `order-processor` appropriately (even down to zero). Notice the `messageCount` property on the scaler's configuration: |
| 211 | + |
| 212 | +```bicep |
| 213 | +metadata: { |
| 214 | + //... |
| 215 | + messageCount: '30' |
| 216 | +} |
| 217 | +``` |
| 218 | + |
| 219 | +This property tells KEDA how many messages each instance of our application can process at the same time. Since the application is single-threaded, we'd normally set this value to 1, resulting in KEDA scaling up our application to match the number of messages waiting in the queue. For example, if 5 messages are waiting, KEDA will scale our app up to 5 instances. In our scenario, we set a `maxReplicas` value of 10, so KEDA scales upt to 10 instances. |
| 220 | + |
217 | 221 | ## Next steps
|
218 | 222 |
|
219 | 223 | [Learn more about using Dapr components with Azure Container Apps.](./dapr-overview.md)
|
0 commit comments