Partially improve support for `--cpus` from Docker CLI (#23747)
authorLudovic Henry <luhenry@microsoft.com>
Fri, 5 Apr 2019 16:42:47 +0000 (09:42 -0700)
committerGitHub <noreply@github.com>
Fri, 5 Apr 2019 16:42:47 +0000 (09:42 -0700)
commitaea3b1a80d6c114e3e67bc9521bf39a8a17371d1
tree6ae738c5df8e40f8c3b0e3b73f86cffc06d8e137
parent7f1e506198944a2f82c39beb1c9454ad0984f35b
Partially improve support for `--cpus` from Docker CLI (#23747)

* Round up the value of the CPU limit

In the case where `--cpus` is set to a value very close to the smaller
integer (ex: 1.499999999), it would previously be rounded down. This
would mean that the runtime would only try to take advantage of 1 CPU in
this example, leading to underutilization.

By rounding it up, we augment the pressure on the OS threads scheduler,
but even in the worst case scenario (`--cpus=1.000000001` previously
being rounded to 1, now rounded to 2), we do not observe any
overutilization of the CPU leading to performance degradation.

* Teach the ThreadPool of CPU limits

By making sure we do take the CPU limits into account when computing the
CPU busy time, we ensure we do not have the various heuristic of the
threadpool competing with each other: one trying to allocate more
threads to increase the CPU busy time, and the other one trying to
allocate less threads because there adding more doesn't improve the
throughput.

Let's take the example of a system with 20 cores, and a docker container
with `--cpus=2`. It would mean the total CPU usage of the machine is
2000%, while the CPU limit is 200%. Because the OS scheduler would never
allocate more than 200% of its total CPU budget to the docker container,
the CPU busy time would never get over 200%. From `PAL_GetCpuBusyTime`,
this would indicate that we threadpool threads are mostly doing non-CPU
bound work, meaning we could launch more threads.
src/gc/unix/cgroup.cpp
src/pal/src/misc/cgroup.cpp
src/pal/src/thread/process.cpp