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
+22-4Lines changed: 22 additions & 4 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/04/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,6 +60,7 @@ 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.
60
61
61
62
#### Pending tasks
63
+
62
64
```
63
65
startingNumberOfVMs = 1;
64
66
maxNumberofVMs = 25;
@@ -72,6 +74,7 @@ With this autoscale formula, the pool is initially created with a single VM. The
72
74
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
85
83
86
## Variables
87
+
84
88
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
89
86
90
> [!NOTE]
@@ -96,7 +100,7 @@ You can get and set the values of these service-defined variables to manage the
96
100
| --- | --- |
97
101
| $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
102
| $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> |
103
+
| $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.<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. This is the **recommended value** in most cases. <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
104
101
105
You can get the value of these service-defined variables to make adjustments that are based on metrics from the Batch service:
102
106
@@ -128,6 +132,7 @@ You can get the value of these service-defined variables to make adjustments tha
128
132
>
129
133
130
134
## Types
135
+
131
136
These types are supported in a formula:
132
137
133
138
* double
@@ -157,6 +162,7 @@ These types are supported in a formula:
157
162
* TimeInterval_Year
158
163
159
164
## Operations
165
+
160
166
These operations are allowed on the types that are listed in the previous section.
161
167
162
168
| Operation | Supported operators | Result type |
@@ -212,6 +218,7 @@ Some of the functions that are described in the previous table can accept a list
212
218
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
219
214
220
## <aname="getsampledata"></a>Obtain sample data
221
+
215
222
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
223
217
224
```
@@ -271,6 +278,7 @@ Because there may be a delay in sample availability, it is important to always s
271
278
>
272
279
273
280
## Metrics
281
+
274
282
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
283
276
284
<table>
@@ -317,6 +325,7 @@ You can use both resource and task metrics when you're defining a formula. You a
317
325
</table>
318
326
319
327
## Write an autoscale formula
328
+
320
329
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
330
322
331
First, let's define the requirements for our new autoscale formula. The formula should:
@@ -630,9 +639,11 @@ Error:
630
639
```
631
640
632
641
## Example autoscale formulas
642
+
633
643
Let's look at a few formulas that show different ways to adjust the amount of compute resources in a pool.
634
644
635
645
### Example 1: Time-based adjustment
646
+
636
647
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
648
638
649
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.
> It's highly recommended to use `$NodeDeallocationOption = taskcompletion`, which waits for currently running tasks to finish, and then removes the node from the pool. If you use the default value, `$NodeDeallocationOption = requeue`, the task terminates immediately, wasting what has been run so far, and puts nodes back on the job queue so that they are rescheduled. SFor more information, see the [Variables](#variables) table.
681
+
667
682
### Example 3: Accounting for parallel tasks
683
+
668
684
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
707
691
708
The formula in the following code snippet:
@@ -710,6 +727,7 @@ string formula = string.Format(@"
710
727
```
711
728
712
729
## Next steps
730
+
713
731
*[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
732
* 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