From: Max Carrara <m.carrara@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH v2 pxar 2/2] decoder: aio: improve performance of async file reads
Date: Mon, 31 Jul 2023 15:34:04 +0200 [thread overview]
Message-ID: <20230731133404.859756-2-m.carrara@proxmox.com> (raw)
In-Reply-To: <20230731133404.859756-1-m.carrara@proxmox.com>
In order to bring `aio::Decoder` on par with its `sync` counterpart
as well as `sync::Accessor` and `aio::Accessor`, its input is now
buffered.
As the `tokio` docs mention themselves [0], it can be really
inefficient to directly work with an (unbuffered) `AsyncRead`
instance.
The other aforementioned types already buffer their reads in one way
or another, so wrapping the input reader in `tokio::io::BufReader`
results in a substantial performance gain. [1]
`tokio/io-util` is added as dependency in order to use
`tokio::io::BufReader`.
[0]: https://docs.rs/tokio/1.29.1/tokio/io/struct.BufReader.html
[1]: Tested via examples/compare-read.rs on a large (13GB) pxar archive
Before:
> PXAR Read Performance Comparison
> Running in mode: release
>
> First pass:
> With aio::Decoder: Ok(()) (elapsed: 20.532270177s)
> With sync::Decoder: Ok(()) (elapsed: 3.498566141s)
> With aio::Accessor: Ok(()) (elapsed: 3.978160609s)
> With sync::Accessor: Ok(()) (elapsed: 3.885640895s)
>
> Second pass:
> With aio::Decoder: Ok(()) (elapsed: 18.648986266s)
> With sync::Decoder: Ok(()) (elapsed: 3.617167922s)
> With aio::Accessor: Ok(()) (elapsed: 4.083678211s)
> With sync::Accessor: Ok(()) (elapsed: 4.103763507s)
After:
> PXAR Read Performance Comparison
> Running in mode: release
>
> First pass:
> With aio::Decoder: Ok(()) (elapsed: 9.546522171s)
> With sync::Decoder: Ok(()) (elapsed: 3.535062119s)
> With aio::Accessor: Ok(()) (elapsed: 3.926439101s)
> With sync::Accessor: Ok(()) (elapsed: 3.905232916s)
>
> Second pass:
> With aio::Decoder: Ok(()) (elapsed: 10.633561678s)
> With sync::Decoder: Ok(()) (elapsed: 3.528989778s)
> With aio::Accessor: Ok(()) (elapsed: 3.831093917s)
> With sync::Accessor: Ok(()) (elapsed: 3.848684845s)
Signed-off-by: Max Carrara <m.carrara@proxmox.com>
---
Changes v1 --> v2:
* Include addition of `tokio/io-util` as dependency
* Use new examples/compare-read.rs instead of old custom tool to
measure performance impact
* Use default buffer size (8K) instead of 16K
(I wasn't able to reproduce the performance gains, so ...)
Cargo.toml | 2 +-
src/decoder/aio.rs | 10 +++++++---
2 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/Cargo.toml b/Cargo.toml
index 8669e30..08c0973 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -63,7 +63,7 @@ libc = "0.2"
[features]
default = [ "tokio-io" ]
-tokio-io = [ "tokio" ]
+tokio-io = [ "tokio", "tokio/io-util" ]
tokio-fs = [ "tokio-io", "tokio/fs" ]
full = [ "tokio-fs"]
diff --git a/src/decoder/aio.rs b/src/decoder/aio.rs
index 200dd3d..7cb9c12 100644
--- a/src/decoder/aio.rs
+++ b/src/decoder/aio.rs
@@ -79,14 +79,18 @@ mod tok {
use std::pin::Pin;
use std::task::{Context, Poll};
- /// Read adapter for `futures::io::AsyncRead`
+ use tokio::io::AsyncRead;
+
+ /// Read adapter for `tokio::io::AsyncRead`
pub struct TokioReader<T> {
- inner: T,
+ inner: tokio::io::BufReader<T>,
}
impl<T: tokio::io::AsyncRead> TokioReader<T> {
pub fn new(inner: T) -> Self {
- Self { inner }
+ Self {
+ inner: tokio::io::BufReader::new(inner),
+ }
}
}
--
2.39.2
next prev parent reply other threads:[~2023-07-31 13:34 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-31 13:34 [pbs-devel] [PATCH v2 pxar 1/2] Add `compare-read.rs` to examples and drop feature `async-examples` Max Carrara
2023-07-31 13:34 ` Max Carrara [this message]
2023-07-31 14:57 ` [pbs-devel] [PATCH v2 pxar 2/2] decoder: aio: improve performance of async file reads Fabian Grünbichler
2023-07-31 15:14 ` Max Carrara
2023-08-04 11:32 ` Wolfgang Bumiller
2023-07-31 14:58 ` [pbs-devel] [PATCH v2 pxar 1/2] Add `compare-read.rs` to examples and drop feature `async-examples` Fabian Grünbichler
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230731133404.859756-2-m.carrara@proxmox.com \
--to=m.carrara@proxmox.com \
--cc=pbs-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.