-
Notifications
You must be signed in to change notification settings - Fork 618
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Windows MemorySwappiness Work Around #924
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks pretty good, just a small suggestion.
HostConfig is retrieved from the task and deep copied to a new struct.
I don't see this happening anywhere and don't think it's necessary anyway...
agent/api/task_windows.go
Outdated
// This bug is not noticed when no value is passed in. However, the go-dockerclient client version | ||
// we are using removed the json option omitempty causing this parameter to default to 0 if empty. | ||
// https://github.com/fsouza/go-dockerclient/commit/72342f96fabfa614a94b6ca57d987eccb8a836bf | ||
func (task *Task) platformHostConfigOverride(hostConfig *docker.HostConfig) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I'd probably nest this just a little bit deeper so that the comment you have can be on the part that actually talks about what it does. Something like this:
// platformHostConfigOverrides applies platform-specific overrides to HostConfig options.
func (task *Task) platformHostConfigOverride(hostConfig *docker.HostConfig) {
task.forceDefaultMemorySwappiness(hostConfig)
}
// forceDefaultMemorySwappiness sets the MemorySwappiness field to be -1
// Docker for Windows treats some options differently than Linux [...]
func (task *Task) forceDefaultMemorySwappiness(hostConfig *docker.HostConfig) {
hostConfig.MemorySwappiness = memorySwappinessDefault
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. had a few comments.
agent/api/task_windows.go
Outdated
// we are using removed the json option omitempty causing this parameter to default to 0 if empty. | ||
// https://github.com/fsouza/go-dockerclient/commit/72342f96fabfa614a94b6ca57d987eccb8a836bf | ||
func (task *Task) platformHostConfigOverride(hostConfig *docker.HostConfig) { | ||
hostConfig.MemorySwappiness = memorySwappinessDefault |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like this pattern of passing a reference to data and then modifying it, particularly when we can avoid it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you recommend returning a new copy that has been modified, or moving the method to be attached to hostConfig (i.e. hostConfig.platformOverride())
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We talked offline -- this is fine. It'd be nice to refactor this to have a translator class for task api -> host config... but thats outside the scope here.
@@ -99,3 +103,60 @@ func TestPostUnmarshalWindowsCanonicalPaths(t *testing.T) { | |||
assert.Equal(t, expectedTask.Containers, task.Containers, "Containers should be equal") | |||
assert.Equal(t, expectedTask.Volumes, task.Volumes, "Volumes should be equal") | |||
} | |||
|
|||
func TestWindowsPlatformHostConfigOverride(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could use subtests here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually, i lied. don't do that here :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes look good to me.
Could you please amend the commit messages with the following structure:
pkg: Summary Line
Commit Body
agent/api/task_windows_test.go
Outdated
} | ||
|
||
hostConfig := &docker.HostConfig{ | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: can be in a single line
agent/api/task_windows_test.go
Outdated
// Expects MemorySwappiness option to be set to -1 | ||
|
||
task := &Task{ | ||
Arn: "myArn", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't we just use a minimalist Task
object here ?
agent/api/task_windows_test.go
Outdated
func TestWindowsMemorySwappinessOption(t *testing.T) { | ||
// Testing sending a task to windows overriding MemorySwappiness value | ||
rawHostConfigInput := docker.HostConfig{ | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: can be in a single line
agent/api/task_unix.go
Outdated
const ( | ||
portBindingHostIP = "0.0.0.0" | ||
memorySwappinessDefault = 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this unused ?
Can we add a comment here ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's required to be defined for a test in task_test.go. Adding a comment
Your current commit message describes what the changes are, but not why. I'd prefer it was the other way around. 😄 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, though I'd prefer if you adjusted the commit message before merging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Adds functionality to override HostConfig values in order to pass proper default parameter values, based on platform, to Docker's API. This addresses the MemorySwappiness value which is being set to 0 by default in go-dockerclient.
Clarified comment for platformHostConfigOverride for easier reading. Fixed file endings.
Moved MemorySwappiness override to its own function and make an injection point for future overrides. Added comments to clarify use of memorySwappinessDefault default in task_unix.go Removed properties in the TestWindowsPlatformHostConfigOverride setup tha were unneeded in order to test the functionality.
6dd6f70
to
96ba42c
Compare
Summary
Adds workaround to set MemorySwappiness to -1 for Windows
Implementation details
HostConfig is retrieved from the task and deep copied to a new struct. Platform based values are then overridden for this copy of the HostConfig struct.
Testing
New tests added:
task_windows_test.go - TestWindowsPlatformHostConfigOverride
task_windows_test.go - TestWindowsMemorySwappinessOption
make release
)go build -out amazon-ecs-agent.exe ./agent
)make test
) passgo test -timeout=25s ./agent/...
) passmake run-integ-tests
) pass.\scripts\run-integ-tests.ps1
) passmake run-functional-tests
) pass.\scripts\run-functional-tests.ps1
) passNew tests cover the changes: yes
Description for the changelog
Bug - Workaround for MemorySwapiness bug for Windows
Licensing
This contribution is under the terms of the Apache 2.0 License: yes