-
Notifications
You must be signed in to change notification settings - Fork 824
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
Consider making rayon
dependency of singlepass backend optional
#2261
Comments
Hello, It seems to be a good feature to add indeed. |
Do you have time to try a PR? |
Sure, #2262! One thing I cant fix though is making sure that the code is build with |
I think it'd worth to do the same for other backends. We previously stumbled with rayon-rs/rayon#751 while using Wasmer with cranelift in async environment. |
For solving the threading situation, I was thinking on a bit bigger scope: allowing the user to set the number of threads that a compiler can make use of. use wasmer::{Store, JIT};
use wasmer_compiler_singlepass::Singlepass;
let mut compiler = Singlepass::new();
compiler.num_compilation_threads(1);
// Put it into an engine and add it to the store
let store = Store::new(&JIT::new(compiler).engine()); We can still make use of the Thoughts? |
@syrusakbary not sure that's the right place in the stack for this knob. One of the ideas behind rayon (and (actually, the pool should be global for system, not for app: see Grand Central Dispatch and make job server) So I think the ideal API for the user to utilize only two threads for wasm compilation would be to use something like this: let pool = rayon::ThreadPoolBuilder::new().num_threads(2).build().unwrap();
let compiled_code = pool.install(|| wasmer::compile(code)); So the solution for tunability here is to document that wasmer uses rayon internally, and point users to rayon's docs for this. Note that there's also a difference between a thread pool with one worker and not using a thread pool. Even if the user sets the number of rayon threads to one, this still involves cross-thread communication (and compiling in the rayon machinery, which you might want to avoid for, eg, code size reasons). TL;DR:
EDIT: to clarify, the "would be ideal API" is something that already works. |
2262: Make parallelism optional for singlepass backend r=syrusakbary a=matklad # Description closes #2261 # Review - [ ] Add a short description of the change to the CHANGELOG.md file Co-authored-by: Aleksey Kladov <[email protected]>
Motivation
At near, we are using the singlepass backend because we care about determinism and predictability. In particular, we generally avoid using thread parallelism, to avoid situations where two concurrent bits of functionality decide to take advantage of all cores at the same time and starve each other for CPU. So we need to be able to run wasmer with just a single thread.
We can already do this by configuring rayon's global theradpool, but that's not convenient (you need custom setup code for each
main
and#[test]
), and feels a bit roundabout. Even withRAYON_NUM_THREADS
there's still a (degenerate) thread pool, and unnecessary inter-thread situationProposed solution
I took a quick look at the code, and it seems that making
rayon
optional should be fairly straightforward. Something like:There's even https://github.com/cuviper/rayon-cond, but I am not sure it is worth it.
Alternatives
Controlling this at runtime via
RAYON_NUM_THREADS
orrayon::ThreadPoolBuilder::build_global
is already possible, just inconvenientThe text was updated successfully, but these errors were encountered: