diff --git a/api/compose_test.go b/api/compose_test.go index 0774227434d..85574da6cac 100644 --- a/api/compose_test.go +++ b/api/compose_test.go @@ -15,7 +15,7 @@ func TestCompose(t *testing.T) { CPU: 1250, MemoryMB: 1024, DiskMB: 2048, - IOPS: 1024, + IOPS: 500, Networks: []*NetworkResource{ &NetworkResource{ CIDR: "0.0.0.0/0", @@ -81,7 +81,7 @@ func TestCompose(t *testing.T) { CPU: 1250, MemoryMB: 1024, DiskMB: 2048, - IOPS: 1024, + IOPS: 500, Networks: []*NetworkResource{ &NetworkResource{ CIDR: "0.0.0.0/0", diff --git a/api/tasks_test.go b/api/tasks_test.go index f9ef2d95603..428d178eb2c 100644 --- a/api/tasks_test.go +++ b/api/tasks_test.go @@ -169,7 +169,7 @@ func TestTask_Require(t *testing.T) { CPU: 1250, MemoryMB: 128, DiskMB: 2048, - IOPS: 1024, + IOPS: 500, Networks: []*NetworkResource{ &NetworkResource{ CIDR: "0.0.0.0/0", diff --git a/client/executor/exec_linux.go b/client/executor/exec_linux.go index c837b8a531e..3985fb5fe6a 100644 --- a/client/executor/exec_linux.go +++ b/client/executor/exec_linux.go @@ -87,7 +87,7 @@ func (e *LinuxExecutor) Limit(resources *structs.Resources) error { } if e.cgroupEnabled { - e.configureCgroups(resources) + return e.configureCgroups(resources) } return nil @@ -168,9 +168,9 @@ func (e *LinuxExecutor) cleanTaskDir() error { return errs.ErrorOrNil() } -func (e *LinuxExecutor) configureCgroups(resources *structs.Resources) { +func (e *LinuxExecutor) configureCgroups(resources *structs.Resources) error { if !e.cgroupEnabled { - return + return nil } e.groups = &cgroupConfig.Cgroup{} @@ -204,10 +204,16 @@ func (e *LinuxExecutor) configureCgroups(resources *structs.Resources) { e.groups.CpuShares = int64(resources.CPU) } - if resources.IOPS > 0 { - e.groups.BlkioThrottleReadIOpsDevice = strconv.FormatInt(int64(resources.IOPS), 10) - e.groups.BlkioThrottleWriteIOpsDevice = strconv.FormatInt(int64(resources.IOPS), 10) + if resources.IOPS != 0 { + // Validate it is in an acceptable range. + if resources.IOPS < 10 || resources.IOPS > 1000 { + return fmt.Errorf("resources.IOPS must be between 10 and 1000: %d", resources.IOPS) + } + + e.groups.BlkioWeight = uint16(resources.IOPS) } + + return nil } func (e *LinuxExecutor) runAs(userid string) error { diff --git a/website/source/docs/jobspec/index.html.md b/website/source/docs/jobspec/index.html.md index 173cd041b48..9ed167bef65 100644 --- a/website/source/docs/jobspec/index.html.md +++ b/website/source/docs/jobspec/index.html.md @@ -187,7 +187,7 @@ The `resources` object supports the following keys: * `disk` - The disk required in MB. -* `iops` - The number of IOPS required. +* `iops` - The number of IOPS required given as a weight between 10-1000. * `memory` - The memory required in MB.