Skip to content
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

fs: add set_max_buf_size to tokio::fs::File #6411

Merged
merged 4 commits into from Mar 22, 2024

Conversation

mox692
Copy link
Member

@mox692 mox692 commented Mar 18, 2024

Motivation

#5397 enhanced performance by updating the tokio::fs::File's MAX_BUF from 16KiB to 2MiB for operations involving AsyncWrite / AsyncRead. Related to this, it would also be useful to provide an API that allows to customize this default.

Solution

This introduce a set_max_buf_size to tokio::fs::File to customize the maximum buffer size.
If this is not set, the current default of 2MiB will be applied. In the current implementation, this max_buf_size will be applicable for both read and write operations.

@mox692 mox692 added A-tokio Area: The main tokio crate M-fs Module: tokio/fs labels Mar 18, 2024
tokio/src/fs/file.rs Outdated Show resolved Hide resolved
@mox692
Copy link
Member Author

mox692 commented Mar 19, 2024

Another FB from @Darksonn: https://discord.com/channels/500028886025895936/500336346770964480/1219623744901746788

It would be great to be able to provide this in a sync function, but as far as I've seen, it seems to be difficult to implement in a simple way ...

@carllerche
Copy link
Member

I think it should be doable as a sync function if you set a value somewhere (max buf size) that is checked when the buffer is written to.

@mox692
Copy link
Member Author

mox692 commented Mar 19, 2024

@carllerche
If such an implementation is still acceptable, I think we can do it.
I'll give it a try tomorrow.

@mox692
Copy link
Member Author

mox692 commented Mar 20, 2024

Okay, I think this is ready for another look. The implementation is still simpler than I expected.

Also, I noticed that the inner Buf type is also used for io::Stdin, io::Stdout, but I've left these as they are, using 2MiB. (If we wanted to provide the same means of customization for Stdin, Stdout, we could easily do so.)

@maminrayej maminrayej merged commit f9d78fb into tokio-rs:master Mar 22, 2024
75 checks passed
@mox692 mox692 deleted the configurable_buf_size branch April 13, 2024 06:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate M-fs Module: tokio/fs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants