Skip to content

Commit

Permalink
api,config: rename unbounded memory config
Browse files Browse the repository at this point in the history
rename the unbounded memory config for windows and add update unit tests
  • Loading branch information
adnxn committed Oct 19, 2019
1 parent d0eedb0 commit 541f0d5
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 23 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ additional details on each available environment variable.
| `ECS_CGROUP_PATH` | `/sys/fs/cgroup` | The root cgroup path that is expected by the ECS agent. This is the path that accessible from the agent mount. | `/sys/fs/cgroup` | Not applicable |
| `ECS_CGROUP_CPU_PERIOD` | `10ms` | CGroups CPU period for task level limits. This value should be between 8ms to 100ms | `100ms` | Not applicable |
| `ECS_ENABLE_CPU_UNBOUNDED_WINDOWS_WORKAROUND` | `true` | When `true`, ECS will allow CPU unbounded(CPU=`0`) tasks to run along with CPU bounded tasks in Windows. | Not applicable | `false` |
| `ECS_ENABLE_RAM_UNBOUNDED_WINDOWS_WORKAROUND` | `true` | When `true`, ECS will allow tasks with no memory reservation to run along with memory bounded tasks in Windows. To run a memory unbounded task, omit the memory hard limit and set any memory reservation, it will be ignored. | Not applicable | `false` |
| `ECS_ENABLE_MEMORY_UNBOUNDED_WINDOWS_WORKAROUND` | `true` | When `true`, ECS will ignore the memory reservation parameter (soft limit) to run along with memory bounded tasks in Windows. To run a memory unbounded task, omit the memory hard limit and set any memory reservation, it will be ignored. | Not applicable | `false` |
| `ECS_TASK_METADATA_RPS_LIMIT` | `100,150` | Comma separated integer values for steady state and burst throttle limits for task metadata endpoint | `40,60` | `40,60` |
| `ECS_SHARED_VOLUME_MATCH_FULL_CONFIG` | `true` | When `true`, ECS Agent will compare name, driver options, and labels to make sure volumes are identical. When `false`, Agent will short circuit shared volume comparison if the names match. This is the default Docker behavior. If a volume is shared across instances, this should be set to `false`. | `false` | `false`|
| `ECS_CONTAINER_INSTANCE_PROPAGATE_TAGS_FROM` | `ec2_instance` | If `ec2_instance` is specified, existing tags defined on the container instance will be registered to Amazon ECS and will be discoverable using the `ListTagsForResource` API. Using this requires that the IAM role associated with the container instance have the `ec2:DescribeTags` action allowed. | `none` | `none` |
Expand Down
10 changes: 5 additions & 5 deletions agent/api/task/task_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ type PlatformFields struct {
// CpuUnbounded determines whether a mix of unbounded and bounded CPU tasks
// are allowed to run in the instance
CpuUnbounded bool `json:"cpuUnbounded"`
// RamUnbounded determines whether a mix of unbounded and bounded Memory tasks
// MemoryUnbounded determines whether a mix of unbounded and bounded Memory tasks
// are allowed to run in the instance
RamUnbounded bool `json:"ramUnbounded"`
MemoryUnbounded bool `json:"memoryUnbounded"`
}

var cpuShareScaleFactor = runtime.NumCPU() * cpuSharesPerCore
Expand All @@ -53,8 +53,8 @@ var cpuShareScaleFactor = runtime.NumCPU() * cpuSharesPerCore
func (task *Task) adjustForPlatform(cfg *config.Config) {
task.downcaseAllVolumePaths()
platformFields := PlatformFields{
CpuUnbounded: cfg.PlatformVariables.CPUUnbounded,
RamUnbounded: cfg.PlatformVariables.RAMUnbounded,
CpuUnbounded: cfg.PlatformVariables.CPUUnbounded,
MemoryUnbounded: cfg.PlatformVariables.MemoryUnbounded,
}
task.PlatformFields = platformFields
}
Expand Down Expand Up @@ -124,7 +124,7 @@ func (task *Task) platformHostConfigOverride(hostConfig *dockercontainer.HostCon
}
hostConfig.CPUShares = 0

if hostConfig.Memory <= 0 && task.PlatformFields.RamUnbounded {
if hostConfig.Memory <= 0 && task.PlatformFields.MemoryUnbounded {
// As of version 17.06.2-ee-6 of docker. MemoryReservation is not supported on windows. This ensures that
// this parameter is not passed, allowing to launch a container without a hard limit.
hostConfig.MemoryReservation = 0
Expand Down
18 changes: 8 additions & 10 deletions agent/api/task/task_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,23 +283,21 @@ func TestWindowsMemoryReservationOption(t *testing.T) {
},
},
PlatformFields: PlatformFields{
RamUnbounded: false,
MemoryUnbounded: false,
},
}

// With RamUnbounded set to false, MemoryReservation is not overridden
// With MemoryUnbounded set to false, MemoryReservation is not overridden
config, configErr := testTask.DockerHostConfig(testTask.Containers[0], dockerMap(testTask), defaultDockerClientAPIVersion)
if configErr != nil {
t.Fatal(configErr)
}

assert.Nil(t, configErr)
assert.EqualValues(t, nonZeroMemoryReservationValue, config.MemoryReservation)

// With RamUnbounded set to true, tasks with no memory hard limit will have their memory reservation set to zero
testTask.PlatformFields.RamUnbounded = true
// With MemoryUnbounded set to true, tasks with no memory hard limit will have their memory reservation set to zero
testTask.PlatformFields.MemoryUnbounded = true
config, configErr = testTask.DockerHostConfig(testTask.Containers[0], dockerMap(testTask), defaultDockerClientAPIVersion)
if configErr != nil {
t.Fatal(configErr)
}

assert.Nil(t, configErr)
assert.EqualValues(t, expectedMemoryReservationValue, config.MemoryReservation)
}

Expand Down
11 changes: 6 additions & 5 deletions agent/config/config_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ func DefaultConfig() Config {
ecsRoot := filepath.Join(programData, "Amazon", "ECS")
dataDir := filepath.Join(ecsRoot, "data")
platformVariables := PlatformVariables{
CPUUnbounded: false,
RAMUnbounded: false,
CPUUnbounded: false,
MemoryUnbounded: false,
}
return Config{
DockerEndpoint: "npipe:////./pipe/docker_engine",
Expand Down Expand Up @@ -119,10 +119,11 @@ func (cfg *Config) platformOverrides() {
cfg.TaskCPUMemLimit = ExplicitlyDisabled

cpuUnbounded := utils.ParseBool(os.Getenv("ECS_ENABLE_CPU_UNBOUNDED_WINDOWS_WORKAROUND"), false)
ramUnbounded := utils.ParseBool(os.Getenv("ECS_ENABLE_RAM_UNBOUNDED_WINDOWS_WORKAROUND"), false)
memoryUnbounded := utils.ParseBool(os.Getenv("ECS_ENABLE_MEMORY_UNBOUNDED_WINDOWS_WORKAROUND"), false)

platformVariables := PlatformVariables{
CPUUnbounded: cpuUnbounded,
RAMUnbounded: ramUnbounded,
CPUUnbounded: cpuUnbounded,
MemoryUnbounded: memoryUnbounded,
}
cfg.PlatformVariables = platformVariables
}
Expand Down
17 changes: 17 additions & 0 deletions agent/config/config_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,20 @@ func TestCPUUnboundedWindowsDisabled(t *testing.T) {
assert.NoError(t, err)
assert.False(t, cfg.PlatformVariables.CPUUnbounded)
}

func TestMemoryUnboundedSet(t *testing.T) {
defer setTestRegion()()
defer setTestEnv("ECS_ENABLE_MEMORY_UNBOUNDED_WINDOWS_WORKAROUND", "true")()
cfg, err := NewConfig(ec2.NewBlackholeEC2MetadataClient())
cfg.platformOverrides()
assert.NoError(t, err)
assert.True(t, cfg.PlatformVariables.MemoryUnbounded)
}

func TestMemoryUnboundedWindowsDisabled(t *testing.T) {
defer setTestRegion()()
cfg, err := NewConfig(ec2.NewBlackholeEC2MetadataClient())
cfg.platformOverrides()
assert.NoError(t, err)
assert.False(t, cfg.PlatformVariables.MemoryUnbounded)
}
4 changes: 2 additions & 2 deletions agent/config/types_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type PlatformVariables struct {
// CPUUnbounded specifies if agent can run a mix of CPU bounded and
// unbounded tasks for windows
CPUUnbounded bool
// RAMUnbounded specifies if agent can run a mix of Memory bounded and
// MemoryUnbounded specifies if agent can run a mix of Memory bounded and
// unbounded tasks for windows
RAMUnbounded bool
MemoryUnbounded bool
}

0 comments on commit 541f0d5

Please sign in to comment.