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

Set CPU/Memory in both config and hostconfig #1069

Merged
merged 4 commits into from
Nov 16, 2017

Conversation

richardpen
Copy link

@richardpen richardpen commented Nov 10, 2017

Summary

Fix #616

Implementation details

Set the CPU and memory in both Docker Config and HostConfig

Testing

  • 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
  • Manually tested on windows

New tests cover the changes:

Description for the changelog

Licensing

This contribution is under the terms of the Apache 2.0 License:

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.

Just added some minor nits and suggestions!

@@ -464,6 +464,25 @@ func (task *Task) dockerConfig(container *Container) (*docker.Config, *DockerCli
return config, nil
}

// SetConfigHostConfigCommonFileds sets the same fields in both Config and HostConfig for backward compatibility
func (task *Task) SetConfigHostConfigCommonFileds(container *Container, config *docker.Config, hc *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: typo s/SetConfigHostConfigCommonFileds/SetConfigHostConfigCommonFields

// SetConfigHostConfigCommonFileds sets the same fields in both Config and HostConfig for backward compatibility
func (task *Task) SetConfigHostConfigCommonFileds(container *Container, config *docker.Config, hc *docker.HostConfig) {
// Convert MB to B
dockerMem := int64(container.Memory * 1024 * 1024)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we have a const (bytesPerMegabyte) for this multiplier in task_unix.go.
Could be moved and reused if necessary.

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.

Have you tested this and verified that the memory limit is now properly enforced on Windows?

Also: it seems weird to just blindly set memory in both places. It might make more sense to trigger this behavior in an API version adapter layer so that we move the field to the right place when we're using an API version that requires it.

CHANGELOG.md Outdated
@@ -5,6 +5,7 @@
* Feature - Enable support for task level CPU and memory constraints.
* Bug - Fixed a bug where a task can be blocked in creating state. [#1048](https://github.com/aws/amazon-ecs-agent/pull/1048)
* Bug - Fixed dynamic HostPort in container metadata. [#1052](https://github.com/aws/amazon-ecs-agent/pull/1052)
* Bug - Fixed bug on windows where container memory limits isn't enforced. [#1069](https://github.com/aws/amazon-ecs-agent/pull/1069)
Copy link
Contributor

Choose a reason for hiding this comment

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

s/windows/Windows/
s/isn't/are not/

if dockerMem != 0 && dockerMem < DockerContainerMinimumMemoryInBytes {
dockerMem = DockerContainerMinimumMemoryInBytes
}
cpuShare := task.dockerCPUShares(container.CPU)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we really want to set CPU in both?

Copy link
Author

Choose a reason for hiding this comment

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

Based on this commit, it looks like the memory and cpu are both moved to HostConfig, I will modify this only be set when the api version is <1.18

@@ -28,6 +29,8 @@ const (
memorySwappinessDefault = -1
)

var cpus = runtime.NumCPU() * 1024
Copy link
Contributor

Choose a reason for hiding this comment

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

How about "cpuShareScaleFactor"?

return err
}

dockerAPIVersion_1_18, err := docker.NewAPIVersion("1.18")
Copy link
Contributor

Choose a reason for hiding this comment

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

APIVersion is just []int. I think you could do this:

var dockerAPIVersion_1_18 := APIVersion([]int{1,18})

That gets rid of your err.

return err
}

if dockerAPIVersion.GreaterThanOrEqualTo(dockerAPIVersion_1_18) {
Copy link
Contributor

Choose a reason for hiding this comment

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

should we log in an else case?

@@ -106,6 +110,18 @@ func (f *factory) FindKnownAPIVersions() []DockerVersion {
return knownVersions
}

// FindClientAPIVersion returns the version of the client from the map
// TODO we should let go docker client return this version information
Copy link
Contributor

Choose a reason for hiding this comment

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

the TODO seems like a better option, whats stopping us from doing that?

Copy link
Author

Choose a reason for hiding this comment

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

go dockerclient doesn't support this today, we need contribute and update.

Peng Yin added 4 commits November 16, 2017 01:13
Docker moved the Memory from Config into HostConfig where on windows the
memory information in Config wasn't respected. This commit sets the
memory in both Config and HostConfig to make it compatiable.
@richardpen richardpen changed the base branch from dev to windows November 16, 2017 01:13
@richardpen richardpen merged commit 6762134 into aws:windows Nov 16, 2017
@samuelkarp samuelkarp mentioned this pull request Nov 22, 2017
8 tasks
@samuelkarp samuelkarp added this to the 1.16.0 milestone Nov 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants