From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id C54248E08 for ; Mon, 31 Jul 2023 16:57:27 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id A4B60571B for ; Mon, 31 Jul 2023 16:57:27 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Mon, 31 Jul 2023 16:57:26 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id E07F443251 for ; Mon, 31 Jul 2023 16:57:25 +0200 (CEST) Date: Mon, 31 Jul 2023 16:57:17 +0200 From: Fabian =?iso-8859-1?q?Gr=FCnbichler?= To: Proxmox Backup Server development discussion References: <20230731133404.859756-1-m.carrara@proxmox.com> <20230731133404.859756-2-m.carrara@proxmox.com> In-Reply-To: <20230731133404.859756-2-m.carrara@proxmox.com> MIME-Version: 1.0 User-Agent: astroid/0.16.0 (https://github.com/astroidmail/astroid) Message-Id: <1690811866.sqrlbr0udn.astroid@yuna.none> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-SPAM-LEVEL: Spam detection results: 0 AWL 0.069 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - Subject: Re: [pbs-devel] [PATCH v2 pxar 2/2] decoder: aio: improve performance of async file reads X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 31 Jul 2023 14:57:27 -0000 On July 31, 2023 3:34 pm, Max Carrara wrote: > 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. >=20 > As the `tokio` docs mention themselves [0], it can be really > inefficient to directly work with an (unbuffered) `AsyncRead` > instance. >=20 > 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] >=20 > `tokio/io-util` is added as dependency in order to use > `tokio::io::BufReader`. >=20 > [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 >=20 > 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) >=20 > 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) this does look good to me in general, do you have more details about your test pxar file? because for me with a big archive with lots of hardlinks (POM-created mirror): buffered: Time (mean =C2=B1 =CF=83): 17.360 s =C2=B1 0.769 s [User: 2.460 s, = System: 14.345 s] Range (min =E2=80=A6 max): 16.004 s =E2=80=A6 18.225 s 10 runs stock: Time (mean =C2=B1 =CF=83): 20.512 s =C2=B1 1.248 s [User: 3.158 s, = System: 16.510 s] Range (min =E2=80=A6 max): 19.045 s =E2=80=A6 22.176 s 10 runs Summary buffered ran 1.18 =C2=B1 0.09 times faster than stock and for another even bigger (~40G) archive consisting of a PBS .chunks dir: buffered: Time (mean =C2=B1 =CF=83): 138.329 s =C2=B1 3.627 s [User: 19.407 s= , System: 114.824 s] Range (min =E2=80=A6 max): 134.266 s =E2=80=A6 146.754 s 10 runs stock: Time (mean =C2=B1 =CF=83): 179.822 s =C2=B1 3.679 s [User: 26.894= s, System: 144.526 s] Range (min =E2=80=A6 max): 173.166 s =E2=80=A6 186.505 s 10 runs Summary buffered ran 1.30 =C2=B1 0.04 times faster than stock which, while an obvious improvement, is far from your almost 2x speedup ;) >=20 > Signed-off-by: Max Carrara > --- > 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 ...) >=20 > Cargo.toml | 2 +- > src/decoder/aio.rs | 10 +++++++--- > 2 files changed, 8 insertions(+), 4 deletions(-) >=20 > diff --git a/Cargo.toml b/Cargo.toml > index 8669e30..08c0973 100644 > --- a/Cargo.toml > +++ b/Cargo.toml > @@ -63,7 +63,7 @@ libc =3D "0.2" >=20 > [features] > default =3D [ "tokio-io" ] > -tokio-io =3D [ "tokio" ] > +tokio-io =3D [ "tokio", "tokio/io-util" ] > tokio-fs =3D [ "tokio-io", "tokio/fs" ] >=20 > full =3D [ "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}; >=20 > - /// Read adapter for `futures::io::AsyncRead` > + use tokio::io::AsyncRead; > + > + /// Read adapter for `tokio::io::AsyncRead` > pub struct TokioReader { > - inner: T, > + inner: tokio::io::BufReader, > } >=20 > impl TokioReader { > pub fn new(inner: T) -> Self { > - Self { inner } > + Self { > + inner: tokio::io::BufReader::new(inner), > + } > } > } >=20 > -- > 2.39.2 >=20 >=20 >=20 > _______________________________________________ > pbs-devel mailing list > pbs-devel@lists.proxmox.com > https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel >=20 >=20 >=20