Skip to content

Switch Swarm Mode services to NanoCpu#39190

Merged
cpuguy83 merged 1 commit into
moby:masterfrom
ollypom:swarmnanocpu
May 20, 2019
Merged

Switch Swarm Mode services to NanoCpu#39190
cpuguy83 merged 1 commit into
moby:masterfrom
ollypom:swarmnanocpu

Conversation

@ollypom
Copy link
Copy Markdown
Contributor

@ollypom ollypom commented May 8, 2019

- What I did
Today $ docker service create --limit-cpu configures a containers CpuPeriod and CpuQuota variables, this commit switches this to configure a containers NanoCpu variable instead to try and fix #33538 and provide support for limiting CPU on Windows Workloads.

This change makes $ docker service create --limit-cpu the same as $ docker run --cpu as the later is supported on windows. https://docs.microsoft.com/en-us/virtualization/windowscontainers/manage-containers/resource-controls

The reason this change was required is because CPU Period is not supported on Windows today:

$ docker service create --limit-cpu "1.5" --name demo hello-world
8la8dhl7gml1biihijaxzrgwq
overall progress: 0 out of 1 tasks
1/1: invalid option: Windows does not support CPUPeriod

I have tested this change locally on a Linux machine and it now sets the NanoCPU setting correctly and does not set CPU Period / Quota. Note I haven't actually tested this on a Windows Machine though.

- How I did it

- How to verify it

$ docker swarm init

$ docker service create --name demo --limit-cpu ".5" nginx
71vtiore4fonv6dhzpxdby8x5
overall progress: 1 out of 1 tasks
1/1: running   [==================================================>]
verify: Service converged

$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
00fca6ed116d        nginx:latest        "nginx -g 'daemon of…"   24 seconds ago      Up 23 seconds       80/tcp              demo.1.2d6s3s9oao6yzzkyy2althpu2

$ docker inspect 00f | jq '.[].HostConfig.NanoCpus'
500000000

$ docker inspect 00f | jq '.[].HostConfig.CpuPeriod'
0

$ docker inspect 00f | jq '.[].HostConfig.CpuQuota'
0

- Description for the changelog
Support CPU constraints on Windows Swarm Services

- A picture of a cute animal (not mandatory but encouraged)
image

Today `$ docker service create --limit-cpu` configures a containers
`CpuPeriod` and `CpuQuota` variables, this commit switches this to
configure a containers `NanoCpu` variable instead.

Signed-off-by: Olly Pomeroy <[email protected]>
@olljanat
Copy link
Copy Markdown
Contributor

olljanat commented May 9, 2019

@ollypom thanks about this and congrats about your first PR to Moby 🎂

@ollypom
Copy link
Copy Markdown
Contributor Author

ollypom commented May 16, 2019

@olljanat Thanks :) Do you know who would be best, to tag in to take a look and review this?

@thaJeztah
Copy link
Copy Markdown
Member

hm, nice catch; I looked at this PR and wondered if the actual limits would be set, but looks like this was effectively was just dead code (as container create also does this conversion/calculation) 🤔

Verified that the limits are properly set with this PR;

docker service create --name test --limit-cpu=0.5 nginx:alpine


docker exec $(docker ps -q --filter label=com.docker.swarm.service.name=test) sh -c 'cat /sys/fs/cgroup/cpu/cpu.cfs_quota_us /sys/fs/cgroup/cpu/cpu.cfs_period_us'
50000
100000

Copy link
Copy Markdown
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

LGTM

@thaJeztah
Copy link
Copy Markdown
Member

ping @cpuguy83 @yongtang ptal

Copy link
Copy Markdown
Member

@cpuguy83 cpuguy83 left a comment

Choose a reason for hiding this comment

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

LGTM

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.

Docker Swarm mode on Windows Containers: If --limit-cpu is specified the service does not get created.

5 participants