Merge pull request #222 from hashicorp/b-runc-throttle-device

Switch from using cgroups BlkioThrottleReadIOpsDevice to BlkioWeight
This commit is contained in:
Alex Dadgar 2015-10-06 15:47:07 -07:00
commit 9f6ad73e45
4 changed files with 16 additions and 10 deletions

View file

@ -15,7 +15,7 @@ func TestCompose(t *testing.T) {
CPU: 1250, CPU: 1250,
MemoryMB: 1024, MemoryMB: 1024,
DiskMB: 2048, DiskMB: 2048,
IOPS: 1024, IOPS: 500,
Networks: []*NetworkResource{ Networks: []*NetworkResource{
&NetworkResource{ &NetworkResource{
CIDR: "0.0.0.0/0", CIDR: "0.0.0.0/0",
@ -81,7 +81,7 @@ func TestCompose(t *testing.T) {
CPU: 1250, CPU: 1250,
MemoryMB: 1024, MemoryMB: 1024,
DiskMB: 2048, DiskMB: 2048,
IOPS: 1024, IOPS: 500,
Networks: []*NetworkResource{ Networks: []*NetworkResource{
&NetworkResource{ &NetworkResource{
CIDR: "0.0.0.0/0", CIDR: "0.0.0.0/0",

View file

@ -169,7 +169,7 @@ func TestTask_Require(t *testing.T) {
CPU: 1250, CPU: 1250,
MemoryMB: 128, MemoryMB: 128,
DiskMB: 2048, DiskMB: 2048,
IOPS: 1024, IOPS: 500,
Networks: []*NetworkResource{ Networks: []*NetworkResource{
&NetworkResource{ &NetworkResource{
CIDR: "0.0.0.0/0", CIDR: "0.0.0.0/0",

View file

@ -87,7 +87,7 @@ func (e *LinuxExecutor) Limit(resources *structs.Resources) error {
} }
if e.cgroupEnabled { if e.cgroupEnabled {
e.configureCgroups(resources) return e.configureCgroups(resources)
} }
return nil return nil
@ -168,9 +168,9 @@ func (e *LinuxExecutor) cleanTaskDir() error {
return errs.ErrorOrNil() return errs.ErrorOrNil()
} }
func (e *LinuxExecutor) configureCgroups(resources *structs.Resources) { func (e *LinuxExecutor) configureCgroups(resources *structs.Resources) error {
if !e.cgroupEnabled { if !e.cgroupEnabled {
return return nil
} }
e.groups = &cgroupConfig.Cgroup{} e.groups = &cgroupConfig.Cgroup{}
@ -204,10 +204,16 @@ func (e *LinuxExecutor) configureCgroups(resources *structs.Resources) {
e.groups.CpuShares = int64(resources.CPU) e.groups.CpuShares = int64(resources.CPU)
} }
if resources.IOPS > 0 { if resources.IOPS != 0 {
e.groups.BlkioThrottleReadIOpsDevice = strconv.FormatInt(int64(resources.IOPS), 10) // Validate it is in an acceptable range.
e.groups.BlkioThrottleWriteIOpsDevice = strconv.FormatInt(int64(resources.IOPS), 10) 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 { func (e *LinuxExecutor) runAs(userid string) error {

View file

@ -187,7 +187,7 @@ The `resources` object supports the following keys:
* `disk` - The disk required in MB. * `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. * `memory` - The memory required in MB.