Skip to content

Commit

Permalink
Merge pull request #222 from hashicorp/b-runc-throttle-device
Browse files Browse the repository at this point in the history
Switch from using cgroups BlkioThrottleReadIOpsDevice to BlkioWeight
  • Loading branch information
dadgar committed Oct 6, 2015
2 parents bfbdd19 + 50862f8 commit d31d621
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
4 changes: 2 additions & 2 deletions api/compose_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion api/tasks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
18 changes: 12 additions & 6 deletions client/executor/exec_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (e *LinuxExecutor) Limit(resources *structs.Resources) error {
}

if e.cgroupEnabled {
e.configureCgroups(resources)
return e.configureCgroups(resources)
}

return nil
Expand Down Expand Up @@ -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{}
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion website/source/docs/jobspec/index.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down

0 comments on commit d31d621

Please sign in to comment.