| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
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.
There was a problem hiding this comment.
Nice! A couple of comments:
Sorry, something went wrong.
| } | ||
|
|
||
| const cpuMaxString = fs.readFileSync(cpuMaxFile, "utf-8"); | ||
| const cpuLimit = cpuMaxString.split(" ")[0]; |
There was a problem hiding this comment.
Optional: log a warning and return undefined if there are more than two values
Sorry, something went wrong.
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.
Sorry, something went wrong.
| const cpuStartIndex = parseInt(token.charAt(0)); | ||
| const cpuEndIndex = parseInt(token.charAt(2)); |
There was a problem hiding this comment.
I would consider splitting by - in case we have a range like 0-15
Sorry, something went wrong.
There was a problem hiding this comment.
👍 done! Thanks!
Sorry, something went wrong.
| maxThreadsCandidates.push( | ||
| ...["/sys/fs/cgroup/cpuset.cpus.effective", "/sys/fs/cgroup/cpuset.cpus"] | ||
| .map((file) => getCgroupCpuCountFromCpus(file, logger)) | ||
| .filter((count) => count !== undefined && count > 0) |
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.
Sorry, something went wrong.
There was a problem hiding this comment.
Looks good, thanks!
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
We want to respect cgroup constraints 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 check sys/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