From 095dc9ae57d80d3834aa8fcb6daf6cc2be29f5b9 Mon Sep 17 00:00:00 2001 From: Chris Bednarski Date: Tue, 6 Oct 2015 01:47:04 -0700 Subject: [PATCH 1/2] Updated Throttle Read/Write to match upstream changes in runc; now takes a list of ThrottleDevice structs instead of an int --- client/executor/exec_linux.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/client/executor/exec_linux.go b/client/executor/exec_linux.go index c837b8a531ee..79812b75bc7b 100644 --- a/client/executor/exec_linux.go +++ b/client/executor/exec_linux.go @@ -205,8 +205,11 @@ func (e *LinuxExecutor) configureCgroups(resources *structs.Resources) { } if resources.IOPS > 0 { - e.groups.BlkioThrottleReadIOpsDevice = strconv.FormatInt(int64(resources.IOPS), 10) - e.groups.BlkioThrottleWriteIOpsDevice = strconv.FormatInt(int64(resources.IOPS), 10) + throttleDevice := &cgroupConfig.ThrottleDevice{ + Rate: uint64(resources.IOPS), + } + e.groups.BlkioThrottleReadIOPSDevice = append(e.groups.BlkioThrottleReadIOPSDevice, throttleDevice) + e.groups.BlkioThrottleWriteIOPSDevice = append(e.groups.BlkioThrottleWriteIOPSDevice, throttleDevice) } } From 50862f8e3191c9812cc92bb60696def8e8163580 Mon Sep 17 00:00:00 2001 From: Alex Dadgar Date: Tue, 6 Oct 2015 15:44:01 -0700 Subject: [PATCH 2/2] Switch to using BlkioWeight --- api/compose_test.go | 4 ++-- api/tasks_test.go | 2 +- client/executor/exec_linux.go | 19 +++++++++++-------- website/source/docs/jobspec/index.html.md | 2 +- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/api/compose_test.go b/api/compose_test.go index 0774227434d9..85574da6cac8 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 f9ef2d956030..428d178eb2ca 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 79812b75bc7b..3985fb5fe6a8 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,13 +204,16 @@ func (e *LinuxExecutor) configureCgroups(resources *structs.Resources) { e.groups.CpuShares = int64(resources.CPU) } - if resources.IOPS > 0 { - throttleDevice := &cgroupConfig.ThrottleDevice{ - Rate: uint64(resources.IOPS), + 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.BlkioThrottleReadIOPSDevice = append(e.groups.BlkioThrottleReadIOPSDevice, throttleDevice) - e.groups.BlkioThrottleWriteIOPSDevice = append(e.groups.BlkioThrottleWriteIOPSDevice, throttleDevice) + + 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 173cd041b483..9ed167bef653 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.