-
-
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
Why tokio uses blocking file io under the hood? #2926
Comments
I'm not super familiar with the situation on Windows, but there is no suitable async file IO support in Linux besides the very new io_uring API, which is only supported on the newest Linux kernels. |
What do you mean by As for Windows, .Net developers use Overlapped IO: Their code quite complicated however. I believe, it is because their |
You can find some details on io_uring in Tokio here #2411. However note that we are currently focusing on getting 0.3 and 1.0 out in 2020, so io_uring has been postponed until we have finished that transition as described in #2692 (comment). |
Windows Overlapped I/O (including using it with IOCP) is not a perfect solution: |
There are also another caveat of Overlapped IO So if tokio will use Windows async file I/O, it is better to use IOCP for it. |
Closing due to inactivity. If someone wants to make this happen, I would suggest opening a proposal issue w/ implementation details and a discussion on how to manage IOCP file ops still being synchronous at times. |
General
As I see, tokio uses blocking IO on filesystem.
Calls here a
sys::run
.Which is actually a
spawn::blocking
.Which runs blocking code on special thread pool.
Is it intentional or just temporary solution? If first, why we need to use blocking fs API when there is async one?
Describe the solution you'd like
I am new at async programming so would describe only Windows version of solution. However, I think there is a Linux version too.
I suggest to use either OVERLAPPING IO or Input-Output Completion Ports.
AFAIK, you are already using IOCP for network in mio but I don't know how complex to integrate file IO with this.
For the overlapped IO I made little example. It is quite ugly but enough to show basic schema.
The overlapped IO requires using separate thread for handling FS IO but I think it is still better than few threads from pool blocked on FS.
Additional context
According to this table latency of disk read can be 12 times slower than network request so why use async on net and threads on disk?
Maybe I can help?
If you like to start using this file async APIs, I can offer my help. I can start from implementing Windows APIs then do Linux thing, however, I can't do anything for MacOS or other OSes.
However, I will need some guidance:
std::fs::File
and let users explicitely use tokio blocking tasks?The text was updated successfully, but these errors were encountered: