-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
os: add availableParallelism() #45895
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,19 @@ The operating system-specific end-of-line marker. | |
* `\n` on POSIX | ||
* `\r\n` on Windows | ||
|
||
## `os.availableParallelism()` | ||
|
||
<!-- YAML | ||
added: REPLACEME | ||
--> | ||
|
||
* Returns: {integer} | ||
|
||
Returns an estimate of the default amount of parallelism a program should use. | ||
Always returns a value greater than zero. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some explanation about how that estimate is reached would be helpful here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here is the PR that added this functionality to libuv - libuv/libuv@f250c6c. If you have some exact text you'd like to see based on that, I'm happy to add it. The CI has been so flaky (and frustrating) that I don't want to go back and forth with pushing changes, running the CI, making more changes, etc. - I'd rather just ship whatever suggestions you have. Alternatively, a docs update could be added after the fact since the CI requirements for docs only changes are much lower. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The implementation of My suggestions are to a) link to the libuv documentation, b) leave it out, or c) say we consult the animating spirits inside the computer. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd like to see how option C plays out. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Or, if nothing else, link to the libuv documentation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does not answer the question of what it does inside of a cgroup, which is the primary problem with cpus() There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not mentioned because it's oblivious to the presence of cgroups. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not a fan of adding new features that replicate open bugs in existing functionality. Also #28855 specifically asks for this problem (cgoups causing process count to be wrong) to be fixed, which is what my question is asking. Obliviousness is exactly the problem. cpus().length is oblivious to cgroups and gives the processor count of the host, not what's available to the container. If the answer is 'no', we still don't have a solution to the issue that was marked closed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm lousy at reading C code, but I think this is saying: libuv/libuv@f250c6c That There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's oblivious in the "cache oblivious algorithm" sense: libuv doesn't have to care whether cgroups are active or not; if the container is set up properly, it'll produce the right answer. |
||
|
||
This function is a small wrapper about libuv's [`uv_available_parallelism()`][]. | ||
|
||
## `os.arch()` | ||
|
||
<!-- YAML | ||
|
@@ -127,6 +140,10 @@ The properties included on each object include: | |
`nice` values are POSIX-only. On Windows, the `nice` values of all processors | ||
are always 0. | ||
|
||
`os.cpus().length` should not be used to calculate the amount of parallelism | ||
available to an application. Use | ||
[`os.availableParallelism()`](#osavailableparallelism) for this purpose. | ||
|
||
## `os.devNull` | ||
|
||
<!-- YAML | ||
|
@@ -1340,3 +1357,4 @@ The following process scheduling constants are exported by | |
[`process.arch`]: process.md#processarch | ||
[`process.platform`]: process.md#processplatform | ||
[`uname(3)`]: https://linux.die.net/man/3/uname | ||
[`uv_available_parallelism()`]: https://docs.libuv.org/en/v1.x/misc.html#c.uv_available_parallelism |
Uh oh!
There was an error while loading. Please reload this page.