<story><title>Go, Containers, and the Linux Scheduler</title><url>https://www.riverphillips.dev/blog/go-cfs/</url></story><parent_chain></parent_chain><comment><author>dekhn</author><text>The common problem I see across many languages is: applications detect machine cores by looking at &amp;#x2F;proc&amp;#x2F;cpuinfo.  However, in a docker container (or other container technology), that file looks the same as the container host (listing all cores, regardless of how few have been assigned to the container).&lt;p&gt;I wondered for a while if docker could make a fake &amp;#x2F;proc&amp;#x2F;cpuinfo that apps could parse that just listed &amp;quot;docker cpus&amp;quot; allocated to the job, but upon further reflection, that probably wouldn&amp;#x27;t work for many reasons.</text></comment>
<story><title>Go, Containers, and the Linux Scheduler</title><url>https://www.riverphillips.dev/blog/go-cfs/</url></story><parent_chain></parent_chain><comment><author>dilyevsky</author><text>This is subtly incorrect - as far as Docker is concerned CFS cgroup extension has several knobs to tune - cfs_quota_us, cfs_period_us (typical default is 100ms not a second) and shares. When you set shares you get weighted proportional scheduling (but only when there&amp;#x27;s contention). The former two enforce strict quota. Don&amp;#x27;t use Docker&amp;#x27;s --cpu flag and instead use --cpu-shares to avoid (mostly useless) quota enforcement.&lt;p&gt;From Linux docs:&lt;p&gt;&lt;pre&gt;&lt;code&gt;  - cpu.shares: The weight of each group living in the same hierarchy, that
    translates into the amount of CPU it is expected to get. Upon cgroup creation,
    each group gets assigned a default of 1024. The percentage of CPU assigned to
    the cgroup is the value of shares divided by the sum of all shares in all
    cgroups in the same level.
  - cpu.cfs_period_us: The duration in microseconds of each scheduler period, for
    bandwidth decisions. This defaults to 100000us or 100ms. Larger periods will
    improve throughput at the expense of latency, since the scheduler will be able
    to sustain a cpu-bound workload for longer. The opposite of true for smaller
    periods. Note that this only affects non-RT tasks that are scheduled by the
    CFS scheduler.
  - cpu.cfs_quota_us: The maximum time in microseconds during each cfs_period_us
    in for the current group will be allowed to run. For instance, if it is set to
    half of cpu_period_us, the cgroup will only be able to peak run for 50 % of
    the time. One should note that this represents aggregate time over all CPUs
    in the system. Therefore, in order to allow full usage of two CPUs, for
    instance, one should set this value to twice the value of cfs_period_us.&lt;/code&gt;&lt;/pre&gt;</text></comment>