This PR improves the performance of fs module when reading files in particular for the file stream implementation.
By refactoring the fs file stream and preferring std::fs::File instead of its tokio async variant, the fs module performance improves significantly when doing file io reads resulting in ~79% more req/sec using ~57% less memory in Linux (according to my tests). However, a similar result should also be expected in Unix targets.
Results
Here is a generic benchmark in Linux just to illustrate.
Basically, ~79.33% more requests per second utilizing ~57.14% less memory.
Context
Below I highlight a quote from the Tokio website talking about Linux io_uring support which I think is self-explanatory.
All tokio-uring operations are truly async, unlike APIs provided by tokio::fs, which run on a thread pool. Using synchronous filesystem operations from a thread pool adds significant overhead. With io-uring, we can perform both network and file system operations asynchronously from the same thread. But, io-uring is a lot more.
– https://tokio.rs/blog/2021-07-tokio-uring
Credits
Not all are mine, there are other people involved in making this possible like the https://github.com/weihanglo/sfz project (inspiration) as well as contributors to SWS.
--
We're enjoying this optimization in SWS so that's why I share it with the warp folks too 😅.
This PR improves the performance of
fs
module when reading files in particular for the file stream implementation.By refactoring the
fs
file stream and preferringstd::fs::File
instead of its tokio async variant, thefs
module performance improves significantly when doing file io reads resulting in~79%
more req/sec using~57%
less memory in Linux (according to my tests). However, a similar result should also be expected in Unix targets.Results
Here is a generic benchmark in Linux just to illustrate.
The
examples/file.rs
was used in the tests.Basically,
~79.33%
more requests per second utilizing~57.14%
less memory.Context
Below I highlight a quote from the Tokio website talking about Linux
io_uring
support which I think is self-explanatory.Credits
Not all are mine, there are other people involved in making this possible like the https://github.com/weihanglo/sfz project (inspiration) as well as contributors to SWS.
--
We're enjoying this optimization in SWS so that's why I share it with the warp folks too 😅.
Let me know what are your thoughts on this.