-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
make bazel cpu counter container aware #5042
Comments
Giving to philwo@, who's much more of an expert in this area than I am. |
Note to self: We can get the CPUs available inside a standard Docker container via: We can get the memory limits via: |
Mostly just subscribing to this ... but I have to say the way bazel subverts the Linux CPU mask is quite annoying. It starts a number of parallel tasks equal to the number of logical processors in the machine, yes, that's weird, but it's not as weird as the fact that it runs on all CPUs regardless of the fact that I run it under The only effective workaround I know is to create a cgroup without access to other CPUs and run the build inside that. |
As of JDK 11, `Runtime#availableProcessors` on Linux is aware of cgroup resource limits and thus behaves as expected in containers, whereas `/proc/cpuinfo` still reports the number of logical processors available to the host. Unfortunately, the JVM-internal `os::total_memory` function, which similarly takes cgroup limits into account when computing the available RAM, does not seem to be accessible from Java. https://hg.openjdk.java.net/jdk/hs/rev/7f22774a5f42#l6.178 Fixes bazelbuild#5042 Closes bazelbuild#16512. RELNOTES[INC]: Bazel's local CPU resource on Linux is now container aware. Use `--local_cpu_resources`, `--loading_phase_threads` or `--jobs` to override. PiperOrigin-RevId: 515032721 Change-Id: I103ee25920d6908545ce6bf03d9c42c604c8589b
https://github.com/bazelbuild/bazel/blob/827007729889126cd7e07a08116f9bcb82f819a9/src/main/java/com/google/devtools/build/lib/actions/LocalHostResourceManagerLinux.java
reads the number of CPUs from /proc/cpuinfo. AFAIK, Docker doesn't virtualize /proc/ , so if you try to control resource usage on a machine with Docker CPU limits, bazel will disregard this an thrash the machine.
The text was updated successfully, but these errors were encountered: