-
Notifications
You must be signed in to change notification settings - Fork 52
bench: add tokio spawn_blocking + std fs benchmark #375
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
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: MrCroxx <[email protected]>
Signed-off-by: MrCroxx <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have leaved the comments and explanations according to the bench results. I think you need to edit your code to make the benchmark fair.
let mut buffer = [0u8; BUFFER_SIZE]; | ||
for &offset in *offsets { | ||
let file = file.clone(); | ||
buffer = tokio::task::spawn_blocking(move || { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this function, every read operation is performed in a new spawn_blocking
closure. It should be a little faster than read_tokio
because it uses seek_read
or read_at
instead of seek
+ read
.
for _i in 0..iter { | ||
let mut file = std::fs::File::open(path).unwrap(); | ||
let len = *len; | ||
buffer = tokio::task::spawn_blocking(move || { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this function, all read operations are performed inside the same spawn_blocking
closure. Why it's not as fast as read_all_std
? Because you open the file inside the for loop. The open-file operation costs a lot.
let content = content.clone(); | ||
|
||
tokio::task::spawn_blocking(move || { | ||
for offset in offsets.iter() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this function, all write operations are performed inside the same spawn_blocking
closure. It should be as fast as write_std
.
file.seek(SeekFrom::Start(0)).unwrap(); | ||
let mut write_len = 0; | ||
let total_len = content.len(); | ||
while write_len < total_len { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this function, all write operations are performed inside the same spawn_blocking
closure. It should be as fast as write_all_std
.
Hi. Thank you for providing the crate
compio
. 🥰This PR introduces tokio
spawn_blocking
+std
case for fs benchmark.The benchmark shows that compio works really good on reads. However, the write part is slower than tokio spawn_blocking + std. I'm not sure if I've done it correctly. Could you please help? 🙏
Raw output: