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

Disable threading when on single core hardware #2372

Merged
merged 1 commit into from
Jun 13, 2020

Conversation

faern
Copy link
Contributor

@faern faern commented Jun 10, 2020

An improvement that will (at least temporarily) fix #2365.

No need to run a thread pool if the number of available CPUs/cores is one anyway. So it can fall back to the special single threaded mode in that case. The single threaded mode uses less memory so it's really useful on low end machines, such as the Raspberry Pi zero and similar.

Since setting the RUSTUP_IO_THREADS environment variable to zero on one now produces the same result as "disabled" did previously the "disabled" value does not need to exist any longer, and the code can be simpler if it just needs to be an integer directly. Since the variable was regarded as unstable in the docs I thought it was fine to change how it behaved.

This new code also prints a warning on stderr if RUSTUP_IO_THREADS is set to an invalid value, instead of just silently falling back to automatically detecting the number of cores.

I'm still working on trying to get this tested locally. But the Rpi zero is incredibly slow at compiling such a big project 😅 At least it builds. So I figured I could submit the PR and get some feedback.

@faern
Copy link
Contributor Author

faern commented Jun 10, 2020

Seems to work as intended on a machine with many cores. So testing successful. But I have not tried on the Raspberry pi yet to see if it actually solves #2365 without having to set custom variables.

src/diskio/mod.rs Outdated Show resolved Hide resolved
@rbtcollins
Copy link
Contributor

I suggest cross-compiling for the pi, it will be a lot faster, even with the time to get setup :).

@faern
Copy link
Contributor Author

faern commented Jun 10, 2020

Can you show me a guide for getting that set up on a macOS machine and I'd be super happy.

@rbtcollins
Copy link
Contributor

Can you show me a guide for getting that set up on a macOS machine and I'd be super happy.

https://dev.to/jeikabu/raspberry-pi-zero-raspbian-rust-primer-3aj6

@rbtcollins
Copy link
Contributor

@kinnison seeking your thoughts: this is backwards incompatible with the disabled value, but RUSTUP_IO_THREADS is markedunstable, so I'm ok taking the heat if folk do find they have scripts they have to update: depending on unstable interfaces should be done by version locking the dependencies anyway.

Copy link
Contributor

@rbtcollins rbtcollins left a comment

Choose a reason for hiding this comment

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

I'm ok with this - thank you.

There's various bits of code golf that could be done differently but nothing consequential enough to be worth asking for it to be changed. (e.g. chain_err can take a string, for instance).

@faern
Copy link
Contributor Author

faern commented Jun 11, 2020

Ok. I know chain_err can take a string. But you had so insanely many ErrorKind variants so I assumed the preferred style was to have explicit error kinds for everything. I did not spend that much time researching all existing chain_err instances. I can easily change it if you prefer an "opaque" string error.

@faern
Copy link
Contributor Author

faern commented Jun 11, 2020

There's various bits of code golf that could be done differently

Feel free to tell me your opinions. I do care deeply about code cleanliness and I thought this was the nicest way of writing this. Separating getting the value out and actually creating the executor etc.

@rbtcollins
Copy link
Contributor

Ok then :) - I try to balance obsession with contributor time :). And Rustup is a quite old codebase with lots of hair on it :). I think taking a string is generally good when an error comes from just one location, making an explicit enum entry for reuse is only worth it when well, we need to reuse it. Or for matching, which is very rare.

The Ok here could be factored to the outside of the expression:

 Ok(match thread_count {
        0 | 1 => Box::new(immediate::ImmediateUnpacker::new()),
        n => Box::new(threaded::Threaded::new(notify_handler, n)),
    })

Generally with error-chain the pattern is to import @ from errors :

use crate::errors::{...} -> use crate::errors::* - its one of the reasons we're trying to move away from it :).

@rbtcollins
Copy link
Contributor

Anyhow, this is ready to merge - I've chatted with @kinnison about the env var change on discord. If you could rebase your changes to remove the exploratory changes, I'll merge this. Thanks!

@faern faern force-pushed the disable-threading-on-single-core branch from 5fcf13a to 9790256 Compare June 11, 2020 22:14
@faern
Copy link
Contributor Author

faern commented Jun 11, 2020

The Ok here could be factored to the outside of the expression

Yeah.. I did not try that since it usually leads to not so nice formatting. But in this case it actually did not add an extra level of indentation so it's fine! I changed it :)

use crate::errors::{...} -> use crate::errors::* - its one of the reasons we're trying to move away from it :).

I'm not a fan of wildcard imports. Makes it super hard to know what comes from where. And yeah, error-chain is pretty ancient at this point :/

I also made the error into just a string, as you wished. Now it should be ready for merge.

@rbtcollins rbtcollins merged commit 2880f30 into rust-lang:master Jun 13, 2020
@rbtcollins
Copy link
Contributor

Thank yoiu

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to install rustc on Raspberry PI W due to low memory
2 participants