Skip to content
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

Use available_parallelism instead of num_cpus #10427

Merged
merged 2 commits into from
Mar 8, 2022

Conversation

weihanglo
Copy link
Member

@weihanglo weihanglo commented Feb 26, 2022

Status: blocked on rust-lang/rust#92697


Just realized that we can drop one dependency 🎉

Also, we don't want to block timing data output, so if parallelism data is not available, the table will display ncpu=n/a instead.

image

`std::thread::available_parallelism` has been stabilized since 1.59.0.

Also, we don't want to block timing data output, so if parallelism
data is not available the table will display `ncpu=n/a` instead.
@rust-highfive
Copy link

r? @ehuss

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 26, 2022
let jobs = jobs.or(cfg.jobs).unwrap_or(::num_cpus::get() as u32);
let jobs = match jobs.or(cfg.jobs) {
Some(j) => j,
None => available_parallelism()?.get() as u32,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could the error-propagation here have some context indicating what the error is? (e.g. something like "failed to determine the amount of parallelism available")

@ehuss
Copy link
Contributor

ehuss commented Feb 28, 2022

I get the impression that available_parallelism is not the same as num_cpus. num_cpus takes things like cgroups and affinity into consideration. Maybe @joshtriplett can speak to the differences, but I'm concerned that it may change behavior in things like Docker.

@weihanglo
Copy link
Member Author

@weihanglo weihanglo closed this Mar 1, 2022
@weihanglo weihanglo deleted the drop-num_cpus branch March 1, 2022 13:13
@joshtriplett
Copy link
Member

@ehuss @weihanglo available_parallelism currently has a PR under review to take cgroups into account. I'd suggest leaving this PR open and blocking it on rust-lang/rust#92697 .

@weihanglo weihanglo restored the drop-num_cpus branch March 2, 2022 11:32
@weihanglo weihanglo reopened this Mar 2, 2022
@weihanglo weihanglo marked this pull request as draft March 2, 2022 11:49
@weihanglo weihanglo marked this pull request as ready for review March 8, 2022 17:02
@joshtriplett
Copy link
Member

available_parallelism in current std now respects cgroups, so we can switch to it without any regressions.

@bors r+

@bors
Copy link
Contributor

bors commented Mar 8, 2022

📌 Commit 4f706ae has been approved by joshtriplett

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 8, 2022
@bors
Copy link
Contributor

bors commented Mar 8, 2022

⌛ Testing commit 4f706ae with merge 6d11f9e...

@bors
Copy link
Contributor

bors commented Mar 8, 2022

☀️ Test successful - checks-actions
Approved by: joshtriplett
Pushing 6d11f9e to master...

@bors bors merged commit 6d11f9e into rust-lang:master Mar 8, 2022
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Mar 9, 2022
Update cargo

11 commits in 3d6970d50e30e797b8e26b2b9b1bdf92dc381f34..65c82664263feddc5fe2d424be0993c28d46377a
2022-02-28 19:29:07 +0000 to 2022-03-09 02:32:56 +0000
- Remove remaining 2 warn(clippy::*) instances (rust-lang/cargo#10438)
- Use `available_parallelism` instead of `num_cpus` (rust-lang/cargo#10427)
- Wait up to one second while waiting for curl (rust-lang/cargo#10456)
- Improve code coverage (rust-lang/cargo#10460)
- Don't recommend leaking tokens into the console history (rust-lang/cargo#10458)
- fix some typos (rust-lang/cargo#10454)
- Use `extend` instead of `push`ing in a loop (rust-lang/cargo#10453)
- Use locked_version more (rust-lang/cargo#10449)
- Disable dependabot (rust-lang/cargo#10443)
- Update git2 dependencies (rust-lang/cargo#10442)
- Stop gating stable features (rust-lang/cargo#10434)
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Mar 9, 2022
Update cargo

11 commits in 3d6970d50e30e797b8e26b2b9b1bdf92dc381f34..65c82664263feddc5fe2d424be0993c28d46377a
2022-02-28 19:29:07 +0000 to 2022-03-09 02:32:56 +0000
- Remove remaining 2 warn(clippy::*) instances (rust-lang/cargo#10438)
- Use `available_parallelism` instead of `num_cpus` (rust-lang/cargo#10427)
- Wait up to one second while waiting for curl (rust-lang/cargo#10456)
- Improve code coverage (rust-lang/cargo#10460)
- Don't recommend leaking tokens into the console history (rust-lang/cargo#10458)
- fix some typos (rust-lang/cargo#10454)
- Use `extend` instead of `push`ing in a loop (rust-lang/cargo#10453)
- Use locked_version more (rust-lang/cargo#10449)
- Disable dependabot (rust-lang/cargo#10443)
- Update git2 dependencies (rust-lang/cargo#10442)
- Stop gating stable features (rust-lang/cargo#10434)
@weihanglo weihanglo deleted the drop-num_cpus branch March 14, 2022 05:54
@ehuss ehuss added this to the 1.61.0 milestone Apr 7, 2022
ehuss added a commit to ehuss/cargo that referenced this pull request Jun 8, 2022
This reverts commit 6d11f9e, reversing
changes made to c5cdd25.
bors added a commit that referenced this pull request Jun 8, 2022
[beta] Revert #10427: switch from num_cpus

This temporarily reverts #10427 (Use available_parallelism instead of num_cpus) per the discussion at rust-lang/rust#97549. `available_parallelism` does not handle cgroups v1 on Linux unlike num_cpus. I am concerned that this potentially affects a significant percentage of users. For example, Docker just added cgroups v2 support last year. Various Linux distributions have only recently switched to it as the default. The following is what I can find on the web:

* Fedora (since 31)
* Arch Linux (since April 2021)
* openSUSE Tumbleweed (since c. 2021)
* Debian GNU/Linux (since 11)
* Ubuntu (since 21.10)
* RHEL and RHEL-like distributions (since 9)

This also appears to affect CircleCI.

The consequence is that Cargo ends up using too much parallelism and can run out of memory.

I'm not sure what to do about 1.63.  If std adds support for cgroups v1, then I don't think there is anything to do there. Otherwise I think we should revert similarly if that doesn't happen.
weihanglo added a commit to weihanglo/cargo that referenced this pull request Jun 8, 2022
This reverts commit 6d11f9e, reversing
changes made to c5cdd25.
bors added a commit that referenced this pull request Jun 9, 2022
Revert #10427: switch from num_cpus

Same as #10737 but on nightly
Hezuikn pushed a commit to Hezuikn/cargo that referenced this pull request Sep 22, 2022
This reverts commit 6d11f9e, reversing
changes made to c5cdd25.
Hezuikn pushed a commit to Hezuikn/cargo that referenced this pull request Sep 22, 2022
This reverts commit 6d11f9e, reversing
changes made to c5cdd25.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants