-
-
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
tokio::fs
+ async is 1-2 orders of magnitude slower than a blocking version
#3664
Comments
I mean, we already know that it is never going to be as fast as using the blocking APIs directly. Did you try with a non-blocking |
Sorry, not sure what you mean by non-blocking My setup is described here in detail, with code and perf data.
There are several things at play here. First there's overhead from async, then from In any case 25x to 64x slow-down from going to |
What I meant to suggest was to replace It is a big slowdown, and there have been several examples of people building really slow benchmarks and finding some trivial change to their code that yields a massive speedup, but those were all for reading the contents of the files. I think ultimately you are just running into a lot of back-and-forth between a bunch of threads, and that is just expensive. |
@Darksonn let me try to clarify. As I explained in the README.md there are several branches, each has its own implementation:
If there is a trivial change to my code that can make, say, |
I've done more testing on other platforms:
This means that the issue is either Linux specific (unlikely) or WSL2 specific (seems more likely). I don't have a native linux box at hand to test this out now. I also tried different version of |
I tried running it on my laptop which is a native Linux box, but
There were all built with |
Great, so Could you try to increase the nofile limit and try |
Sure.
|
Thank you! |
My main opinion on issues like this one is that if someone submits a PR that improves the speed of filesystem operations, I am happy to add those improvements (#3518 is an example), but it is not my a sufficiently large priority to spend time looking for fixes myself. People who need speedups for their fs ops can get already get speedups now by moving the operation into a single |
@Darksonn that’s fair. To be clear, I don’t expect you spending time to diagnose the issue and come up with a fix, we all have different priorities and it’s fine. The way I see it - this perf characteristics are surprising at the very least, so creating an issue is like putting a stick to the ground to tell “We’re aware of this”, and then maybe
However, I can also see that this types of issues may be seen as not directly actionable. Which is totally fair. If this is the case for And in any case, I apologise for the inconvenience if I had missed something about this in the guidelines. |
Updated benchmarks https://github.com/artempyanykh/rdu:
On Windows perf. profile is very different from Linux; naive async version is ~2.2x slower which is kind of acceptable. |
This is referred to in this talk Java and Rust by Yishai Galatzer. They used Tokio async fs operations (on a benchmark) and compared that with Java NIO. IMO, it unfairly pitches Rust as being too slow compared to Java, which is of course not really true. |
Version
1.4.0
Platform
64-bit WSL2 Linux:
Linux 4.19.104-microsoft-standard #1 SMP x86_64 x86_64 x86_64 GNU/Linux
Description
The code is in this repo. The setup is explained in the README.
TL;DR:
du -hs
with blocking and async APIs.std::fs
is about 35% slower thandu
, not bad.tokio::fs
but processes files sequentially is 64x! slower than the blocking version.FuturesUnordered
andselect!
is 2.5x faster than the sequential version, but still 25x slower than a simple blocking version.I understand that
tokio::fs
usesstd::fs
under the hood, that there's no non-blocking system API to FS (modulo 'io-uring' but 🤷♂️), thatasync
has inherent overhead especially if the disk cache is hot and there's not much waiting on blocking calls.However, 25x (not saying 64x) just feels too extreme of a slowdown, so I wonder
tokio::fs
code needs tuning/optimization,The text was updated successfully, but these errors were encountered: