You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/batch/batch-automatic-scaling.md
+26-7Lines changed: 26 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,14 +12,14 @@ ms.service: batch
12
12
ms.topic: article
13
13
ms.tgt_pltfrm:
14
14
ms.workload: multiple
15
-
ms.date: 06/20/2017
15
+
ms.date: 10/08/2019
16
16
ms.author: lahugh
17
17
ms.custom: H1Hack27Feb2017
18
18
19
19
---
20
-
# Create an automatic scaling formula for scaling compute nodes in a Batch pool
20
+
# Create an automatic formula for scaling compute nodes in a Batch pool
21
21
22
-
Azure Batch can automatically scale pools based on parameters that you define. With automatic scaling, Batch dynamically adds nodes to a pool as task demands increase, and removes compute nodes as they decrease. You can save both time and money by automatically adjusting the number of compute nodes used by your Batch application.
22
+
Azure Batch can automatically scale pools based on parameters that you define. With automatic scaling, Batch dynamically adds nodes to a pool as task demands increase, and removes compute nodes as they decrease. You can save both time and money by automatically adjusting the number of compute nodes used by your Batch application.
23
23
24
24
You enable automatic scaling on a pool of compute nodes by associating with it an *autoscale formula* that you define. The Batch service uses the autoscale formula to determine the number of compute nodes that are needed to execute your workload. Compute nodes may be dedicated nodes or [low-priority nodes](batch-low-pri-vms.md). Batch responds to service metrics data that is collected periodically. Using this metrics data, Batch adjusts the number of compute nodes in the pool based on your formula and at a configurable interval.
25
25
@@ -35,6 +35,7 @@ This article discusses the various entities that make up your autoscale formulas
35
35
>
36
36
37
37
## Automatic scaling formulas
38
+
38
39
An automatic scaling formula is a string value that you define that contains one or more statements. The autoscale formula is assigned to a pool's [autoScaleFormula][rest_autoscaleformula] element (Batch REST) or [CloudPool.AutoScaleFormula][net_cloudpool_autoscaleformula] property (Batch .NET). The Batch service uses your formula to determine the target number of compute nodes in the pool for the next interval of processing. The formula string cannot exceed 8 KB, can include up to 100 statements that are separated by semicolons, and can include line breaks and comments.
39
40
40
41
You can think of automatic scaling formulas as a Batch autoscale "language." Formula statements are free-formed expressions that can include both service-defined variables (variables defined by the Batch service) and user-defined variables (variables that you define). They can perform various operations on these values by using built-in types, operators, and functions. For example, a statement might take the following form:
@@ -59,28 +60,33 @@ The target number of nodes may be higher, lower, or the same as the current numb
59
60
Below are examples of two autoscale formulas, which can be adjusted to work for most scenarios. The variables `startingNumberOfVMs` and `maxNumberofVMs` in the example formulas can be adjusted to your needs.
With this autoscale formula, the pool is initially created with a single VM. The `$PendingTasks` metric defines the number of tasks that are running or queued. The formula finds the average number of pending tasks in the last 180 seconds and sets the `$TargetDedicatedNodes` variable accordingly. The formula ensures that the target number of dedicated nodes never exceeds 25 VMs. As new tasks are submitted, the pool automatically grows. As tasks complete, VMs become free one by one and the autoscaling formula shrinks the pool.
71
74
72
75
This formula scales dedicated nodes, but can be modified to apply to scale low-priority nodes as well.
This example creates a pool that starts with 25 low-priority nodes. Every time a low-priority node is preempted, it is replaced with a dedicated node. As with the first example, the `maxNumberofVMs` variable prevents the pool from exceeding 25 VMs. This example is useful for taking advantage of low-priority VMs while also ensuring that only a fixed number of preemptions will occur for the lifetime of the pool.
82
87
83
88
## Variables
89
+
84
90
You can use both **service-defined** and **user-defined** variables in your autoscale formulas. The service-defined variables are built in to the Batch service. Some service-defined variables are read-write, and some are read-only. User-defined variables are variables that you define. In the example formula shown in the previous section, `$TargetDedicatedNodes` and `$PendingTasks` are service-defined variables. Variables `startingNumberOfVMs` and `maxNumberofVMs` are user-defined variables.
85
91
86
92
> [!NOTE]
@@ -96,7 +102,7 @@ You can get and set the values of these service-defined variables to manage the
96
102
| --- | --- |
97
103
| $TargetDedicatedNodes |The target number of dedicated compute nodes for the pool. The number of dedicated nodes is specified as a target because a pool may not always achieve the desired number of nodes. For example, if the target number of dedicated nodes is modified by an autoscale evaluation before the pool has reached the initial target, then the pool may not reach the target. <br /><br /> A pool in an account created with the Batch Service configuration may not achieve its target if the target exceeds a Batch account node or core quota. A pool in an account created with the User Subscription configuration may not achieve its target if the target exceeds the shared core quota for the subscription.|
98
104
| $TargetLowPriorityNodes |The target number of low-priority compute nodes for the pool. The number of low-priority nodes is specified as a target because a pool may not always achieve the desired number of nodes. For example, if the target number of low-priority nodes is modified by an autoscale evaluation before the pool has reached the initial target, then the pool may not reach the target. A pool may also not achieve its target if the target exceeds a Batch account node or core quota. <br /><br /> For more information on low-priority compute nodes, see [Use low-priority VMs with Batch (Preview)](batch-low-pri-vms.md). |
99
-
| $NodeDeallocationOption |The action that occurs when compute nodes are removed from a pool. Possible values are:<ul><li>**requeue**--Terminates tasks immediately and puts them back on the job queue so that they are rescheduled.<li>**terminate**--Terminates tasks immediately and removes them from the job queue.<li>**taskcompletion**--Waits for currently running tasks to finish and then removes the node from the pool.<li>**retaineddata**--Waits for all the local task-retained data on the node to be cleaned up before removing the node from the pool.</ul> |
105
+
| $NodeDeallocationOption |The action that occurs when compute nodes are removed from a pool. Possible values are:<ul><li>**requeue**-- The default value. Terminates tasks immediately and puts them back on the job queue so that they are rescheduled. This action ensures the target number of nodes is reach as quickly as possible, but may be less efficient, as any running tasks will be interrupted and have to be restarted, wasting any work they had already done. <li>**terminate**--Terminates tasks immediately and removes them from the job queue.<li>**taskcompletion**--Waits for currently running tasks to finish and then removes the node from the pool. Use this option to avoid tasks being interrupted and requeued, wasting any work the task has done. <li>**retaineddata**--Waits for all the local task-retained data on the node to be cleaned up before removing the node from the pool.</ul> |
100
106
101
107
You can get the value of these service-defined variables to make adjustments that are based on metrics from the Batch service:
102
108
@@ -128,6 +134,7 @@ You can get the value of these service-defined variables to make adjustments tha
128
134
>
129
135
130
136
## Types
137
+
131
138
These types are supported in a formula:
132
139
133
140
* double
@@ -157,6 +164,7 @@ These types are supported in a formula:
157
164
* TimeInterval_Year
158
165
159
166
## Operations
167
+
160
168
These operations are allowed on the types that are listed in the previous section.
161
169
162
170
| Operation | Supported operators | Result type |
@@ -212,6 +220,7 @@ Some of the functions that are described in the previous table can accept a list
212
220
The *doubleVecList* value is converted to a single *doubleVec* before evaluation. For example, if `v = [1,2,3]`, then calling `avg(v)` is equivalent to calling `avg(1,2,3)`. Calling `avg(v, 7)` is equivalent to calling `avg(1,2,3,7)`.
213
221
214
222
## <aname="getsampledata"></a>Obtain sample data
223
+
215
224
Autoscale formulas act on metrics data (samples) that is provided by the Batch service. A formula grows or shrinks pool size based on the values that it obtains from the service. The service-defined variables that were described previously are objects that provide various methods to access data that is associated with that object. For example, the following expression shows a request to get the last five minutes of CPU usage:
216
225
217
226
```
@@ -271,6 +280,7 @@ Because there may be a delay in sample availability, it is important to always s
271
280
>
272
281
273
282
## Metrics
283
+
274
284
You can use both resource and task metrics when you're defining a formula. You adjust the target number of dedicated nodes in the pool based on the metrics data that you obtain and evaluate. See the [Variables](#variables) section above for more information on each metric.
275
285
276
286
<table>
@@ -317,13 +327,15 @@ You can use both resource and task metrics when you're defining a formula. You a
317
327
</table>
318
328
319
329
## Write an autoscale formula
330
+
320
331
You build an autoscale formula by forming statements that use the above components, then combine those statements into a complete formula. In this section, we create an example autoscale formula that can perform some real-world scaling decisions.
321
332
322
333
First, let's define the requirements for our new autoscale formula. The formula should:
323
334
324
335
1. Increase the target number of dedicated compute nodes in a pool if CPU usage is high.
325
-
2. Decrease the target number of dedicated compute nodes in a pool when CPU usage is low.
326
-
3. Always restrict the maximum number of dedicated nodes to 400.
336
+
1. Decrease the target number of dedicated compute nodes in a pool when CPU usage is low.
337
+
1. Always restrict the maximum number of dedicated nodes to 400.
338
+
1. When reducing the number of nodes, do not remove nodes that are running tasks; if necessary, wait until tasks have finished to remove nodes.
327
339
328
340
To increase the number of nodes during high CPU usage, define the statement that populates a user-defined variable (`$totalDedicatedNodes`) with a value that is 110 percent of the current target number of dedicated nodes, but only if the minimum average CPU usage during the last 10 minutes was above 70 percent. Otherwise, use the value for the current number of dedicated nodes.
329
341
@@ -630,9 +642,11 @@ Error:
630
642
```
631
643
632
644
## Example autoscale formulas
645
+
633
646
Let's look at a few formulas that show different ways to adjust the amount of compute resources in a pool.
634
647
635
648
### Example 1: Time-based adjustment
649
+
636
650
Suppose you want to adjust the pool size based on the day of the week and time of day. This example shows how to increase or decrease the number of nodes in the pool accordingly.
637
651
638
652
The formula first obtains the current time. If it's a weekday (1-5) and within working hours (8 AM to 6 PM), the target pool size is set to 20 nodes. Otherwise, it's set to 10 nodes.
// Set node deallocation mode - keep nodes active only until tasks finish
679
+
// Set node deallocation mode - let running tasks finish before removing a node
664
680
$NodeDeallocationOption=taskcompletion;
665
681
```
666
682
667
683
### Example 3: Accounting for parallel tasks
684
+
668
685
This example adjusts the pool size based on the number of tasks. This formula also takes into account the [MaxTasksPerComputeNode][net_maxtasks] value that has been set for the pool. This approach is useful in situations where [parallel task execution](batch-parallel-node-tasks.md) has been enabled on your pool.
This example shows a C# code snippet with an autoscale formula that sets the pool size to a specified number of nodes for an initial time period. Then it adjusts the pool size based on the number of running and active tasks after the initial time period has elapsed.
690
708
691
709
The formula in the following code snippet:
@@ -710,6 +728,7 @@ string formula = string.Format(@"
710
728
```
711
729
712
730
## Next steps
731
+
713
732
*[Maximize Azure Batch compute resource usage with concurrent node tasks](batch-parallel-node-tasks.md) contains details about how you can execute multiple tasks simultaneously on the compute nodes in your pool. In addition to autoscaling, this feature may help to lower job duration for some workloads, saving you money.
714
733
* For another efficiency booster, ensure that your Batch application queries the Batch service in the most optimal way. See [Query the Azure Batch service efficiently](batch-efficient-list-queries.md) to learn how to limit the amount of data that crosses the wire when you query the status of potentially thousands of compute nodes or tasks.
0 commit comments