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
@@ -44,13 +44,30 @@ The target number of nodes might be higher, lower, or the same as the current nu
44
44
45
45
The following examples show 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.
46
46
47
+
#### Pending tasks
48
+
49
+
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 and the autoscaling formula shrinks the pool.
50
+
51
+
This formula scales dedicated nodes, but can be modified to apply to scale Spot nodes as well.
> Currently, Batch Service has limitations with the resolution of the pending tasks. When a task is added to the job, it's also added into a internal queue used by Batch service for scheduling. If the task is deleted before it can be scheduled, the task might persist within the queue, causing it to still be counted in `$PendingTasks`. This deleted task will eventually be cleared from the queue when Batch gets chance to pull tasks from the queue to schedule with idle nodes in the Batch pool.
47
63
48
64
#### Preempted nodes
49
65
50
66
This example creates a pool that starts with 25 Spot nodes. Every time a Spot node is preempted, it's 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 Spot VMs while also ensuring that only a fixed number of preemptions occur for the lifetime of the pool.
@@ -59,9 +76,61 @@ You'll learn more about [how to create autoscale formulas](#write-an-autoscale-f
59
76
60
77
## Variables
61
78
62
-
You can use *user-defined* variables in your autoscale formulas.
79
+
You can use both *service-defined* and *user-defined* variables in your autoscale formulas.
80
+
81
+
The service-defined variables are built in to the Batch service. Some service-defined variables are read-write, and some are read-only.
82
+
83
+
User-defined variables are variables that you define. In the previous example, `$TargetDedicatedNodes` and `$PendingTasks` are service-defined variables, while `startingNumberOfVMs` and `maxNumberofVMs` are user-defined variables.
84
+
85
+
> [!NOTE]
86
+
> Service-defined variables are always preceded by a dollar sign ($). For user-defined variables, the dollar sign is optional.
87
+
88
+
The following tables show the read-write and read-only variables defined by the Batch service.
89
+
90
+
### Read-write service-defined variables
63
91
64
-
User-defined variables are variables that you define. In the example, `startingNumberOfVMs` and `maxNumberofVMs` are user-defined variables. For user-defined variables, the dollar sign is optional.
92
+
You can get and set the values of these service-defined variables to manage the number of compute nodes in a pool.
93
+
94
+
| Variable | Description |
95
+
| --- | --- |
96
+
| $TargetDedicatedNodes |The target number of dedicated compute nodes for the pool. Specified as a target because a pool might 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, the pool might not reach the target. <br><br> A pool in an account created in Batch service mode might not achieve its target if the target exceeds a Batch account node or core quota. A pool in an account created in user subscription mode might not achieve its target if the target exceeds the shared core quota for the subscription.|
97
+
| $TargetLowPriorityNodes |The target number of Spot compute nodes for the pool. Specified as a target because a pool might not always achieve the desired number of nodes. For example, if the target number of Spot nodes is modified by an autoscale evaluation before the pool has reached the initial target, the pool might not reach the target. A pool might also not achieve its target if the target exceeds a Batch account node or core quota. <br><br> For more information on Spot compute nodes, see [Use Spot VMs with Batch](batch-spot-vms.md). |
98
+
| $NodeDeallocationOption |The action that occurs when compute nodes are removed from a pool. Possible values are:<br>- **requeue**: The default value. Ends tasks immediately and puts them back on the job queue so that they're rescheduled. This action ensures the target number of nodes is reached as quickly as possible. However, it might be less efficient, because any running tasks are interrupted and then must be restarted. <br>- **terminate**: Ends tasks immediately and removes them from the job queue.<br>- **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.<br>- **retaineddata**: Waits for all the local task-retained data on the node to be cleaned up before removing the node from the pool. |
99
+
100
+
> [!NOTE]
101
+
> The `$TargetDedicatedNodes` variable can also be specified using the alias `$TargetDedicated`. Similarly, the `$TargetLowPriorityNodes` variable can be specified using the alias `$TargetLowPriority`. If both the fully named variable and its alias are set by the formula, the value assigned to the fully named variable takes precedence.
102
+
103
+
### Read-only service-defined variables
104
+
105
+
You can get the value of these service-defined variables to make adjustments that are based on metrics from the Batch service.
106
+
107
+
> [!IMPORTANT]
108
+
> Job release tasks aren't currently included in variables that provide task counts, such as `$ActiveTasks` and `$PendingTasks`. Depending on your autoscale formula, this can result in nodes being removed with no nodes available to run job release tasks.
109
+
110
+
> [!TIP]
111
+
> These read-only service-defined variables are *objects* that provide various methods to access data associated with each. For more information, see [Obtain sample data](#obtain-sample-data) later in this article.
112
+
113
+
| Variable | Description |
114
+
| --- | --- |
115
+
| $CPUPercent |The average percentage of CPU usage. |
116
+
| $ActiveTasks |The number of tasks that are ready to execute but aren't yet executing. This includes all tasks that are in the active state and whose dependencies have been satisfied. Any tasks that are in the active state but whose dependencies haven't been satisfied are excluded from the `$ActiveTasks` count. For a multi-instance task, `$ActiveTasks` includes the number of instances set on the task.|
117
+
| $RunningTasks |The number of tasks in a running state. |
118
+
| $PendingTasks |The sum of `$ActiveTasks` and `$RunningTasks`. |
119
+
| $SucceededTasks |The number of tasks that finished successfully. |
120
+
| $FailedTasks |The number of tasks that failed. |
121
+
| $TaskSlotsPerNode |The number of task slots that can be used to run concurrent tasks on a single compute node in the pool. |
122
+
| $CurrentDedicatedNodes |The current number of dedicated compute nodes. |
123
+
| $CurrentLowPriorityNodes |The current number of Spot compute nodes, including any nodes that have been preempted. |
124
+
| $UsableNodeCount | The number of usable compute nodes. |
125
+
| $PreemptedNodeCount | The number of nodes in the pool that are in a preempted state. |
126
+
127
+
> [!WARNING]
128
+
> Select service-defined variables will be retired after **31 March 2024** as noted in the table above. After the retirement
129
+
> date, these service-defined variables will no longer be populated with sample data. Please discontinue use of these variables
130
+
> before this date.
131
+
132
+
> [!NOTE]
133
+
> Use `$RunningTasks` when scaling based on the number of tasks running at a point in time, and `$ActiveTasks` when scaling based on the number of tasks that are queued up to run.
65
134
66
135
## Types
67
136
@@ -160,7 +229,7 @@ You can use both resource and task metrics when you define a formula. You adjust
160
229
161
230
| Metric | Description |
162
231
|----------|--------------|
163
-
| Resource | Resource metrics are based on the CPU, the bandwidth, the memory usage of compute nodes, and the number of nodes.<br><br>These service-defined variables are useful for making adjustments based on node count:<br>- $TargetDedicatedNodes <br>- $TargetLowPriorityNodes <br>- $CurrentDedicatedNodes <br>- $CurrentLowPriorityNodes <br>- $PreemptedNodeCount <br>- $UsableNodeCount <br><br>These service-defined variables are useful for making adjustments based on node resource usage: <br>- $CPUPercent <br>- $WallClockSeconds <br>- $MemoryBytes <br>- $DiskBytes <br>- $DiskReadBytes <br>- $DiskWriteBytes <br>- $DiskReadOps <br>- $DiskWriteOps <br>- $NetworkInBytes <br>- $NetworkOutBytes |
232
+
| Resource | Resource metrics are based on the CPU, the bandwidth, the memory usage of compute nodes, and the number of nodes.<br><br>These service-defined variables are useful for making adjustments based on node count:<br>- $TargetDedicatedNodes <br>- $TargetLowPriorityNodes <br>- $CurrentDedicatedNodes <br>- $CurrentLowPriorityNodes <br>- $PreemptedNodeCount <br>- $UsableNodeCount <br><br>These service-defined variables are useful for making adjustments based on node resource usage: <br>- $CPUPercent |
164
233
| Task | Task metrics are based on the status of tasks, such as Active, Pending, and Completed. The following service-defined variables are useful for making pool-size adjustments based on task metrics: <br>- $ActiveTasks <br>- $RunningTasks <br>- $PendingTasks <br>- $SucceededTasks <br>- $FailedTasks |
0 commit comments