-
Notifications
You must be signed in to change notification settings - Fork 29
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
Remove futures_cpupool in favor of tokio #7
Conversation
Previously, a dedicated cpupool was spun up to run hashing and verification in a non-blocking fashion. This is unfortunate given that there is usually already a threadpool running: the Tokio threadpool. This patch changes the code to run non-blocking hashing and verification on the tokio threadpool instead, to avoid configuring and creating a separate one. It uses tokio_threadpool::blocking to ensure that it does not hold up other Futures while doing so. Note that this removes the ability to configure the number of threads used to perform non-blocking compute, and instead places that responsibility on whomever sets up the `tokio::Runtime`. This is *probably* better, but does change the API. Furthermore, the `non_blocking` methods now _only_ work under `tokio` (actix uses tokio btw), and will not work in non-tokio asynchronous deployments (although those should be rare).
79f4a0c
to
ba0370a
Compare
I'm not the author of this crate, but I do have some concerns over this PR:
|
I agree! It would make sense to move the futures/non-blocking stuff under a
If all they want to do is hash in parallel, then I think they should do so using
It depends how you count "badness". The user now needs to configure two threadpools instead of one, and also try to figure out how many threads to give each one. If you instead just have one pool, you can let that pool figure it out on its own. It also means we avoid making the user run two threadpools that behave differently, and may have to be debugged separately if something misbehaves.
I'm not sure I fully buy this argument. The whole point of non-blocking is that you are also doing other things, and you need to make progress on those too. If you gave all the cores to compute-heavy tasks, then you wouldn't make any progress on those other asynchronous tasks. If indeed all you want to do is hash in parallel, then
This is true. You can set the number of threads in a tokio pool that are allowed to be |
Hey. Author here. First, let me say it’s so awesome jonhoo that you chose to work on my crate on your livestream! I’m a big fan of your videos and have learned a ton from them. Really appreciate what you’re doing. Second, I’d like to apologize for not engaging sooner, but I have an excuse :). I moved into a new apartment yesterday; so my time has been fully taken up with the move. I probably won’t be able to fully engage on this until the end of the week, as the focus now is unpacking, buying missing furniture, and all the other tasks that come with moving into a new place. In any case, thanks so much for the PR jonhoo and your engagement Migi! I look forward to plugging in soon. |
No worries at all! We all have lives, and they take precedence :) Glad you enjoyed the streams! |
Yeah, no worries @bcmyers. Life comes first! And also, 2 days is not a long time, you certaintly don't need to apologize for that. Actually I have another small nit to pick about the PR. I'm sorry @jonhoo if this comes across as me trying to bring you down or something, that is absolutely not the intention. I enjoyed your livestream a lot! But I did just spent the past few hours thinking about threadpools and tokio's I tried testing this in the code (the examples |
@migi - Still can’t fully engage (am writing from my mobile), by have a quick thought. Did you “git submodule init”? If not, might be your issue as just cloning the repo won’t bring in the C code submodule; you need to initialize it. |
@migi Don't worry about it -- not taking it personally :) The goal for both of us is to make the software better! You're right that we won't actually panic as the doc comment currently states. Instead, it will return |
I don't see why depending on Edit: If the goal is spawning, |
We got rid of tokio::spawn, so we now only need tokio-threadpool!
Ah, good point! Fixed in 61b447c |
@bcmyers Any chance of getting this merged in? |
@jonhoo I get |
My apologies everyone for letting this PR fall by the wayside. @mehcode, I was also having problems getting it to work with |
Previously, a dedicated cpupool was spun up to run hashing and verification in a non-blocking fashion. This is unfortunate given that there is usually already a threadpool running: the Tokio threadpool. This patch changes the code to run non-blocking hashing and verification on tokio's threadpool instead, to avoid configuring and creating a separate one. It uses
tokio_threadpool::blocking
to ensure that it does not hold up other Futures while doing so.Note that this removes the ability to configure the number of threads used to perform non-blocking compute, and instead places that responsibility on whomever sets up the
tokio::Runtime
. This is probably better, but does change the API. Furthermore, thenon_blocking
methods now only work undertokio
(actix uses tokio btw), and will not work in non-tokio asynchronous deployments (although those should be rare).