-
-
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
File reading: Performance regression on 0.2.0-alpha.6 compared to 0.1.22 #1844
Comments
Thanks for calling this out. There is a known performance regression that is temporary. The old strategy for fs ops has not been fully hooked into Tokio 0.2. In short, fs ops should use block_in_place but don’t yet (they did in 0.1, but the scheduler was fully rewritten and not everything is fully hooked up. |
Until this is fixed, is there a recommended workaround? Is it best to just call the sync functions in |
You can call |
Roughly: tokio::task::block_in_place(|| {
std::fs::File::open(...)
}) |
I gave that a try but got a runtime error:
main.rs: #[tokio::main]
async fn main() {
tokio::task::block_in_place(|| {});
} Cargo.toml: [package]
name = "tokio-fs-test"
version = "0.1.0"
authors = ["Nicholas Bishop <nbishop@neverware.com>"]
edition = "2018"
[dependencies]
tokio = { version = "0.2.4", features = ["full"] } |
@nicholasbishop wrap that w/ a There is still some more work to do on this front. |
right now you can't use |
Confirmed that using spawn fixed the error. Thanks for the help :) |
Could this be added to the documentation of |
There have been a bunch of PRs making |
@Darksonn it doesn't look like this was actually fixed. |
Right, I've been meaning to document this better for a while. I opened an issue about it. We can continue the discussion there. |
Version
0.2.0-alpha.6 / 0.1.22, on Rust 1.39 in release mode
Platform
Linux [hostname] 4.19.0-6-amd64 #1 SMP Debian 4.19.67-2+deb10u1 (2019-09-20) x86_64 GNU/Linux
Description
For learning, I played around with different versions of buffer-reading a file and counting its bytes. The sync version and a version using Tokio 0.1.22 are both fast, but the async/await version 0.2.0-alpha.6 is 5 to 6 times slower, spending a lot of time in kernel space. While discussing this in the forum it has been suggested to me to report this here as a possible bug in Tokio's executor.
This synchronous version spends on my system 8-16 ms in userland and 95-120 ms in kernel space (as measured by
time
) after some runs, so that the entire file of 636 MB is in the buffer cache:And this async version using tokio::fs::File and Tokio 0.1.22 is just as efficient.
But this modern async version with 0.2.0-alpha.6 takes 220-320 ms in userland and 345-500 ms in kernel space!
I hope this is not due to some obvious mistake on my part. Thanks!
The text was updated successfully, but these errors were encountered: