Respect Linux cgroup CPU number for --threads value#2083
Merged
Conversation
angelapwen
force-pushed
the
use-cgroup-for-threads
branch
from
January 12, 2024 23:13
9ce1146 to
744f969
Compare
angelapwen
force-pushed
the
use-cgroup-for-threads
branch
2 times, most recently
from
January 22, 2024 12:58
d93d38b to
75788e9
Compare
We want to respect `cgroup` constraints so that when we run in a container, the default max threads value is appropriately set to the maximum number of cores in this container rather than the host OS's. We check both `/sys/fs/cgroup/cpuset.cpus.effective` (`cgroup v2`) and `/sys/fs/cgroup/cpuset.cpus` (`cgroup v1`) to find the number of cores.
angelapwen
force-pushed
the
use-cgroup-for-threads
branch
from
January 22, 2024 13:01
75788e9 to
b0e35ba
Compare
angelapwen
marked this pull request as ready for review
January 22, 2024 13:11
henrymercer
reviewed
Jan 23, 2024
henrymercer
left a comment
Contributor
There was a problem hiding this comment.
Nice! A couple of comments:
| } | ||
|
|
||
| const cpuMaxString = fs.readFileSync(cpuMaxFile, "utf-8"); | ||
| const cpuLimit = cpuMaxString.split(" ")[0]; |
Contributor
There was a problem hiding this comment.
Optional: log a warning and return undefined if there are more than two values
Contributor
Author
There was a problem hiding this comment.
Done! I logged as a debug message rather than warning because I don't think the user necessarily needs to be warned in this case.
angelapwen
force-pushed
the
use-cgroup-for-threads
branch
from
January 23, 2024 12:30
bf7632c to
8e735f0
Compare
henrymercer
reviewed
Jan 23, 2024
Comment on lines
+458
to
+459
| const cpuStartIndex = parseInt(token.charAt(0)); | ||
| const cpuEndIndex = parseInt(token.charAt(2)); |
Contributor
There was a problem hiding this comment.
I would consider splitting by - in case we have a range like 0-15
| maxThreadsCandidates.push( | ||
| ...["/sys/fs/cgroup/cpuset.cpus.effective", "/sys/fs/cgroup/cpuset.cpus"] | ||
| .map((file) => getCgroupCpuCountFromCpus(file, logger)) | ||
| .filter((count) => count !== undefined && count > 0) |
Contributor
There was a problem hiding this comment.
Just to record my understanding, this will filter out any NaNs we get since NaN is not greater than 0.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
We want to respect
cgroupconstraints so that when we run in a container, we respect the limits set for the container rather than use the host OS's number of cores.We check both
/sys/fs/cgroup/cpuset.cpus.effective(cgroup v2) and/sys/fs/cgroup/cpuset.cpus(cgroup v1) to find the number of cores available. We also checksys/fs/cgroup/cpu.max(v1,v2) to calculate the number of cores from the limits set in this file.The max threads value is set to the minimum of these values, and if no values were found in these files, we default to the original value of the host OS.
Merge / deployment checklist