all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Max Carrara <m.carrara@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH pxar 2/2] decoder: aio: improve performance of async file reads
Date: Thu, 20 Jul 2023 19:15:05 +0200	[thread overview]
Message-ID: <20230720171505.1053912-2-m.carrara@proxmox.com> (raw)
In-Reply-To: <20230720171505.1053912-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]

[0]: https://docs.rs/tokio/1.29.1/tokio/io/struct.BufReader.html
[1]: Tested via a custom CLI utility that opens and traverses a
     large (13GB) pxar archive with each decoder and accessor

Before:
> First pass
> With aio::Decoder:   Ok(()) (elapsed: 25.827150007s)
> With sync::Decoder:  Ok(()) (elapsed: 3.577611655s)
> With aio::Accessor:  Ok(()) (elapsed: 3.962754675s)
> With sync::Accessor: Ok(()) (elapsed: 3.961245996s)
>
> Second pass
> With aio::Decoder:   Ok(()) (elapsed: 21.045064325s)
> With sync::Decoder:  Ok(()) (elapsed: 3.644003471s)
> With aio::Accessor:  Ok(()) (elapsed: 4.054085818s)
> With sync::Accessor: Ok(()) (elapsed: 4.036097687s)

After:
> First pass:
> With aio::Decoder:   Ok(()) (elapsed: 7.07321221s)
> With sync::Decoder:  Ok(()) (elapsed: 3.431787191s)
> With aio::Accessor:  Ok(()) (elapsed: 3.930457465s)
> With sync::Accessor: Ok(()) (elapsed: 4.007415416s)
>
> Second pass:
> With aio::Decoder:   Ok(()) (elapsed: 6.826005792s)
> With sync::Decoder:  Ok(()) (elapsed: 3.437391887s)
> With aio::Accessor:  Ok(()) (elapsed: 3.833275725s)
> With sync::Accessor: Ok(()) (elapsed: 3.909827322s)

Signed-off-by: Max Carrara <m.carrara@proxmox.com>
---
 src/decoder/aio.rs | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/src/decoder/aio.rs b/src/decoder/aio.rs
index 200dd3d..174551b 100644
--- a/src/decoder/aio.rs
+++ b/src/decoder/aio.rs
@@ -79,14 +79,20 @@ 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 }
+            // buffer size "sweet spot" - larger sizes don't seem to provide any benefit
+            const BUF_SIZE: usize = 1024 * 16;
+            Self {
+                inner: tokio::io::BufReader::with_capacity(BUF_SIZE, inner),
+            }
         }
     }

--
2.39.2





  reply	other threads:[~2023-07-20 17:15 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-20 17:15 [pbs-devel] [PATCH pxar 1/2] Add dependency on `tokio/io-util` to `tokio-io` feature Max Carrara
2023-07-20 17:15 ` Max Carrara [this message]
2023-07-27  8:50   ` [pbs-devel] [PATCH pxar 2/2] decoder: aio: improve performance of async file reads Fabian Grünbichler
2023-08-04 11:27   ` Wolfgang Bumiller

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=20230720171505.1053912-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.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal