91 lines
2.3 KiB
Plaintext
91 lines
2.3 KiB
Plaintext
---
|
|
layout: docs
|
|
page_title: resources Stanza - Job Specification
|
|
description: |-
|
|
The "resources" stanza describes the requirements a task needs to execute.
|
|
Resource requirements include memory, cpu, and more.
|
|
---
|
|
|
|
# `resources` Stanza
|
|
|
|
<Placement groups={['job', 'group', 'task', 'resources']} />
|
|
|
|
The `resources` stanza describes the requirements a task needs to execute.
|
|
Resource requirements include memory, CPU, and more.
|
|
|
|
```hcl
|
|
job "docs" {
|
|
group "example" {
|
|
task "server" {
|
|
resources {
|
|
cpu = 100
|
|
memory = 256
|
|
|
|
device "nvidia/gpu" {
|
|
count = 2
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
```
|
|
|
|
## `resources` Parameters
|
|
|
|
- `cpu` `(int: 100)` - Specifies the CPU required to run this task in MHz.
|
|
|
|
- `cores` <code>(`int`: <optional>)</code> <sup>1.1 Beta</sup> - Specifies the number of CPU cores to reserve
|
|
for the task. This may not be used with `cpu`.
|
|
|
|
- `memory` `(int: 300)` - Specifies the memory required in MB.
|
|
|
|
- `memory_max` <code>(`int`: <optional>)</code> <sup>1.1 Beta</sup> - Optionally, specifies the maximum memory the task may use, if the client has excess memory capacity, in MB.
|
|
|
|
- `device` <code>([Device][]: <optional>)</code> - Specifies the device
|
|
requirements. This may be repeated to request multiple device types.
|
|
|
|
## `resources` Examples
|
|
|
|
The following examples only show the `resources` stanzas. Remember that the
|
|
`resources` stanza is only valid in the placements listed above.
|
|
|
|
### Cores
|
|
|
|
This example specifies that the task requires 2 reserved cores. With this stanza, Nomad will find
|
|
a client with enough spare capacity to reserve 2 cores exclusively for the task. Unlike the `cpu` field, the
|
|
task will not share cpu time with any other tasks managed by Nomad on the client.
|
|
|
|
```hcl
|
|
resources {
|
|
cores = 2
|
|
}
|
|
```
|
|
|
|
If `cores` and `cpu` are both defined in the same resource stanza, validation of the job will fail.
|
|
|
|
### Memory
|
|
|
|
This example specifies the task requires 2 GB of RAM to operate. 2 GB is the
|
|
equivalent of 2000 MB:
|
|
|
|
```hcl
|
|
resources {
|
|
memory = 2000
|
|
}
|
|
```
|
|
|
|
### Devices
|
|
|
|
This example shows a device constraints as specified in the [device][] stanza
|
|
which require two nvidia GPUs to be made available:
|
|
|
|
```hcl
|
|
resources {
|
|
device "nvidia/gpu" {
|
|
count = 2
|
|
}
|
|
}
|
|
```
|
|
|
|
[device]: /docs/job-specification/device 'Nomad device Job Specification'
|