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

refactor: Refactor oio::Write into poll-based to create more room for optimization #3029

Merged
merged 37 commits into from
Sep 11, 2023

Conversation

Xuanwo
Copy link
Member

@Xuanwo Xuanwo commented Sep 11, 2023

oio::Write used to be

#[async_trait]
trait Write {
  async fn write(&mut self, bs: &dyn oio::WriteBuf) -> Result<usize>;
}

It works, but the total overhead is high. For example:

  • Every call to write needs to build a new BoxFuture<'async_trait, X> (because of async_trait)
  • Implement AsyncWrite requires copy the whole buffer every time.
// FIXME: This will copy the buf everytime, we should avoid this.
let bs = Bytes::copy_from_slice(buf);
let fut = async move {
    let n = w.write(&bs).await?;
    Ok((n, w))
};
self.state = State::Write(Box::pin(fut));

By changing into poll_based, we can only build futures while needed. For services like fs, hdfs, we can poll the writer directly! This change also improves a lot for our buffer logic.

Signed-off-by: Xuanwo <[email protected]>
Signed-off-by: Xuanwo <[email protected]>
Signed-off-by: Xuanwo <[email protected]>
Signed-off-by: Xuanwo <[email protected]>
Signed-off-by: Xuanwo <[email protected]>
Signed-off-by: Xuanwo <[email protected]>
Signed-off-by: Xuanwo <[email protected]>
Signed-off-by: Xuanwo <[email protected]>
Signed-off-by: Xuanwo <[email protected]>
Signed-off-by: Xuanwo <[email protected]>
Signed-off-by: Xuanwo <[email protected]>
Signed-off-by: Xuanwo <[email protected]>
Signed-off-by: Xuanwo <[email protected]>
Signed-off-by: Xuanwo <[email protected]>
Signed-off-by: Xuanwo <[email protected]>
Signed-off-by: Xuanwo <[email protected]>
Signed-off-by: Xuanwo <[email protected]>
Signed-off-by: Xuanwo <[email protected]>
Signed-off-by: Xuanwo <[email protected]>
Signed-off-by: Xuanwo <[email protected]>
Signed-off-by: Xuanwo <[email protected]>
Signed-off-by: Xuanwo <[email protected]>
Signed-off-by: Xuanwo <[email protected]>
Signed-off-by: Xuanwo <[email protected]>
Signed-off-by: Xuanwo <[email protected]>
Signed-off-by: Xuanwo <[email protected]>
Signed-off-by: Xuanwo <[email protected]>
Signed-off-by: Xuanwo <[email protected]>
Signed-off-by: Xuanwo <[email protected]>
Signed-off-by: Xuanwo <[email protected]>
Signed-off-by: Xuanwo <[email protected]>
Signed-off-by: Xuanwo <[email protected]>
Copy link
Member

@suyanhanx suyanhanx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@Xuanwo Xuanwo merged commit 587e2d9 into main Sep 11, 2023
93 checks passed
@Xuanwo Xuanwo deleted the poll-write branch September 11, 2023 11:52
ErrorKind::Unsupported,
"SFTP does not support aborting writes",
))
"HdfsWriter doesn't support abort",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be "SftpWriter doesn't support abort"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be "SftpWriter doesn't support abort"

Oh, my bad. Would you like to help fix this typo?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants