Skip to content

Instantly share code, notes, and snippets.

@briandant
Created October 31, 2019 18:02
Show Gist options
  • Save briandant/1d6d53a46fd3d56e61e651a6241201e9 to your computer and use it in GitHub Desktop.
Save briandant/1d6d53a46fd3d56e61e651a6241201e9 to your computer and use it in GitHub Desktop.

The key question is "What attributes are you checking on the container's metadata?" We ask because it looks like the only thing modified by passing in --cpu is NanoCpus, not Cpus. We can successfully modify NanoCpus via the AVL application, but your application still complains that the cores count is too high.

A container started from the AVL dashboard:

root@prod-iscgseu1-wharfhouse-0:/home/briandant# swarm inspect learner___138ab157___0 | grep -i cpu
            "Cpus": 32,
            "CpuShares": 0,
            "NanoCpus": 8000000000,
            "CpuPeriod": 0,
            "CpuQuota": 0,
            "CpuRealtimePeriod": 0,
            "CpuRealtimeRuntime": 0,
            "CpusetCpus": "",
            "CpusetMems": "",
            "CpuCount": 0,
            "CpuPercent": 0,

Note that Cpus = 32 and NanoCpus = 8000000000 (or 8**10 in Python's notation.)

Then, we run two containers from Docker's command line client, which bypasses the AVL application:

root@prod-iscgseu1-wharfhouse-0:/home/briandant# docker run -itd --cpus 4 se2019ai:19.3.4
b977830cdeaa3ad528778a31e01dfb55fcf3e9d534903454c597174345520d7a
root@prod-iscgseu1-wharfhouse-0:/home/briandant# docker inspect b977830cdeaa3ad528778a31e01dfb55fcf3e9d534903454c597174345520d7a | grep -i cpu
            "CpuShares": 0,
            "NanoCpus": 4000000000,
            "CpuPeriod": 0,
            "CpuQuota": 0,
            "CpuRealtimePeriod": 0,
            "CpuRealtimeRuntime": 0,
            "CpusetCpus": "",
            "CpusetMems": "",
            "CpuCount": 0,
            "CpuPercent": 0,

In this first container, the Cpus flag is not set, but NanoCpus does respond to the --cpus flag.

On a second container, we see further that the --cpus flag changes NanoCpus:

root@prod-iscgseu1-wharfhouse-0:/home/briandant# docker run -itd --cpus 6 se2019ai:19.3.4
0608d1899a0c64896b321906f9ed2c71102b8f36c4aa8310bff7c1323332f88e
root@prod-iscgseu1-wharfhouse-0:/home/briandant# docker inspect 0608d1899a0c64896b321906f9ed2c71102b8f36c4aa8310bff7c1323332f88e|grep -i cpu
            "CpuShares": 0,
            "NanoCpus": 6000000000,
            "CpuPeriod": 0,
            "CpuQuota": 0,
            "CpuRealtimePeriod": 0,
            "CpuRealtimeRuntime": 0,
            "CpusetCpus": "",
            "CpusetMems": "",
            "CpuCount": 0,
            "CpuPercent": 0,

It is odd that our application sets Cpus and the Docker client does not. I need to look into that. But, I don't want to make a change to the application only to then realize that --cpus only modifies NanoCpus.

  1. Can you confirm that you see similar behavior in your environment? What changes when you pass --cpus?
  2. Can you explain how you check for the number of cores available? Do you look only at Cpus?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment