Skip to content
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

Merged
merged 4 commits into from
Aug 28, 2017
Merged

Conversation

cabbruzzese
Copy link
Contributor

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

  • Builds on Linux (make release)
  • Builds on Windows (go build -out amazon-ecs-agent.exe ./agent)
  • Unit tests on Linux (make test) pass
  • Unit tests on Windows (go test -timeout=25s ./agent/...) pass
  • Integration tests on Linux (make run-integ-tests) pass
  • Integration tests on Windows (.\scripts\run-integ-tests.ps1) pass
  • Functional tests on Linux (make run-functional-tests) pass
  • Functional tests on Windows (.\scripts\run-functional-tests.ps1) pass

New 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

@cabbruzzese cabbruzzese changed the title Win swappiness Windows MemorySwappiness Work Around Aug 11, 2017
Copy link
Contributor

@samuelkarp samuelkarp left a 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...

// 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) {
Copy link
Contributor

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
}

Copy link
Contributor

@petderek petderek left a 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.

// 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
Copy link
Contributor

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.

Copy link
Contributor Author

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())

Copy link
Contributor

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) {
Copy link
Contributor

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.

Copy link
Contributor

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 :)

Copy link
Contributor

@vsiddharth vsiddharth left a 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

}

hostConfig := &docker.HostConfig{
}
Copy link
Contributor

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

// Expects MemorySwappiness option to be set to -1

task := &Task{
Arn: "myArn",
Copy link
Contributor

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 ?

func TestWindowsMemorySwappinessOption(t *testing.T) {
// Testing sending a task to windows overriding MemorySwappiness value
rawHostConfigInput := docker.HostConfig{
}
Copy link
Contributor

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

const (
portBindingHostIP = "0.0.0.0"
memorySwappinessDefault = 0
Copy link
Contributor

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 ?

Copy link
Contributor Author

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

@samuelkarp
Copy link
Contributor

Abstracted platformHostConfigOverride in task_windows.go to another
method to clarify the intention of the override. Updated related
comments regarding injection point for HostConfig override values.

Commented on task_unix.go to explain the use of memorySwappinessDefault
constant.

Cleaned up extra lines in task_windows_test.go. Removed unneeded
properties in task object use in TestWindowsPlatformHostConfigOverride.

Your current commit message describes what the changes are, but not why. I'd prefer it was the other way around. 😄

Copy link
Contributor

@samuelkarp samuelkarp left a 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.

Copy link
Contributor

@vsiddharth vsiddharth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM :shipit:

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.
@cabbruzzese cabbruzzese merged commit 15463ab into aws:dev Aug 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants