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: Fix scaling of NanoCPUs (--cpus) on Hyper-V containers #32608

Merged
merged 1 commit into from
Apr 24, 2017

Conversation

darstahl
Copy link
Contributor

Signed-off-by: Darren Stahl [email protected]

- What I did

In current Docker versions, when calculating the result of setting NanoCPUs, it is assumed that all of the host's CPUs are available to the container. This assumption does not hold true for Hyper-V containers on Windows. Since Hyper-V containers are backed by Hyper-V technology, they require an explicit CPU count at creation.

This PR uses NanoCPUs to calculate the number of CPUs to expose to the container, as well as a percentage scaling to apply in order to reach the desired NanoCPUs target.

- How I did it

If NanoCPUs is set on a Hyper-V container, it is rounded up to the next whole CPUCount, and that many cores are enabled in the container. If the NanoCPUs value is not evenly divisible by 1000000000 (one whole CPU), a CPUPercent limit is applied to limit the available CPU resources to match the requested NanoCPUs.

Note that in current Windows releases, Hyper-V container CpuLimit (Percent) does not have the same effect on CPU resources as expected by NanoCPUs. This would result in odd scaling, so in current Windows releases NanoCPUs on Hyper-V containers is implemented with either CpuPercent or CpuCount, but not both (unless NanoCPUs is less than 1000000000). If the provided NanoCPUs value is being rounded, a warning will be provided to the user.

- How to verify it

Manual verification.

PS C:\Users\Administrator> docker run --rm --cpus 11.99 --isolation=hyperv microsoft/windowsservercore
WARNING: Your current OS version does not support Hyper-V containers with NanoCPUs greater than 1000000000 but not divisible by 1000000000, rounded to 12000000000
Microsoft Windows [Version 10.0.14393]
(c) 2016 Microsoft Corporation. All rights reserved.

C:\>
--cpus NanoCPUs CpuCount CpuPercent NanoCPUs (Rounded) CpuCount (Rounded) CpuPercent (Rounded)
0.5 500000000 1 50 500000000 1 50
1 1000000000 1 0 1000000000 1 0
1.1 1100000000 2 55 1000000000 1 0
1.5 1500000000 2 75 2000000000 2 0
11.9 11900000000 12 99 12000000000 12 0

- Description for the changelog

Windows: Fix scaling of NanoCPUs (--cpus) on Hyper-V containers.

@darstahl
Copy link
Contributor Author

/cc @jhowardmsft @jstarks

@darstahl
Copy link
Contributor Author

z failures are unrelated to this change

Copy link
Member

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

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

LGTM 🐸

@lowenna
Copy link
Member

lowenna commented Apr 24, 2017

LGTM. Restarted z but can't get it to pass. Merging as failure is unrelated.

@lowenna lowenna merged commit d0ce488 into moby:master Apr 24, 2017
@darstahl darstahl deleted the WindowsNanoCPUs branch April 26, 2017 17:57
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