-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Introducing block_on_worker
and #[tokio::main_worker]
#5446
Comments
Thanks for the PR. I agree w/ the premise that I believe the performance issues can be addressed without an API change by using the thread that I plan on looking into fixing it in Q2 of this year, but if someone else wants to take a stab, I could probably provide some pointers. The change would not be trivial though as it will require some internal refactoring of the multi-threaded scheduler. |
Thanks for the feedback. The present issue is that users are required to discover the current behaviour. Should we at least further document the use of |
You have my blessing for doc PRs. |
I've just made an interesting discovery while re-factoring some code in my |
I believe that Carl's intended solution is to put a worker thread on the thread where |
Is there a place where we can subscribe to updates around this? |
Hello from 1.5 years in the future. @carllerche did you ever get around to improving this situation? If not, we should re-open this issue or open a new one, because the problem still requires a solution. |
I tried to make progress (see the alt-threaded runtime) but have yet to reach the workable point. I ran out of time, so that effort is stalled. |
Is your feature request related to a problem? Please describe.
Yes. Using
#[tokio::main]
orRuntime
'sblock_on
method directly does not run my main body or future as a worker task. The consequence is a significant drop in performance where my main body or future awaits some synchronisation involving a worker task.For example, this:
...will perform significantly slower than this:
Even on a "current_thread" executor.
The same will apply to any use of
#[tokio::main]
and all benchmarks that useblock_on
(most of what I've seen out there).With the above example, I saw a degradation by a factor of 17 times. My opinion is that the majority of Tokio users would not appreciate the problem and have applications today that perform significantly slower than they can. Where benchmarks are used to provide an indication of performance, they may also be quite inaccurate.
Describe the solution you'd like
In essence, I would like to see a
block_on_worker
method alongside theRuntime
'sblock_on
. This would take a result that isSend
. The new method would be implemented by ablock_on
call with its future performing aspawn
.To complement this new method, I would also like to see a
#[tokio::main_worker]
macro to that callsblock_on_worker
. Our documentation should be enhanced to promote the use of#[tokio::main_worker]
.Describe alternatives you've considered
An alternative considered was to change the default implementation of
#[tokio::main]
so that it callsblock_on_worker
. However, this would not be backward-compatible due to the requirement of the future's return type to beSend
.A macro attribute such as
#[tokio::main(spawn)]
could also achieve the same goal, however, I feel that that looks like optional behaviour. I believe that#[tokio::main_worker]
is what people want most of the time and would present more nicely.Additional context
My original PR illustrates the problem further by providing a benchmark. There is some discussion on that PR also.
#5440
The text was updated successfully, but these errors were encountered: