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)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 3B1C58DB3 for ; Mon, 31 Jul 2023 16:58:15 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 23E2C575A for ; Mon, 31 Jul 2023 16:58:15 +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)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Mon, 31 Jul 2023 16:58:14 +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 34FC0432C8 for ; Mon, 31 Jul 2023 16:58:14 +0200 (CEST) Date: Mon, 31 Jul 2023 16:58:07 +0200 From: Fabian =?iso-8859-1?q?Gr=FCnbichler?= To: Proxmox Backup Server development discussion References: <20230731133404.859756-1-m.carrara@proxmox.com> In-Reply-To: <20230731133404.859756-1-m.carrara@proxmox.com> MIME-Version: 1.0 User-Agent: astroid/0.16.0 (https://github.com/astroidmail/astroid) Message-Id: <1690815455.m9tfzd24y4.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 1/2] Add `compare-read.rs` to examples and drop feature `async-examples` 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:58:15 -0000 On July 31, 2023 3:34 pm, Max Carrara wrote: > `compare-read.rs` may be used to compare read speeds between pxar > accessors and decoders, both synchronous and asynchronous versions. >=20 > The `async-examples` feature is dropped in favour of declaring > `[dev-dependencies]` in `Cargo.toml`. >=20 > Signed-off-by: Max Carrara > --- just a note for when this gets applied - both patches obviously change d/control, so that needs a follow-up commit with the updated version > Changes v1 --> v2: > * Remove addition of `tokio/io-util` as dependency > * Add example `compare-read` > * Remove feature `async-example` in favour of `[dev-dependencies]` >=20 > Cargo.toml | 20 +++--- > examples/compare-read.rs | 150 +++++++++++++++++++++++++++++++++++++++ > 2 files changed, 162 insertions(+), 8 deletions(-) > create mode 100644 examples/compare-read.rs >=20 > diff --git a/Cargo.toml b/Cargo.toml > index d120e70..8669e30 100644 > --- a/Cargo.toml > +++ b/Cargo.toml > @@ -15,7 +15,10 @@ exclude =3D [ > [[example]] > name =3D "apxar" > path =3D "examples/apxar.rs" > -required-features =3D [ "async-example" ] > + > +[[example]] > +name =3D "compare-read" > +path =3D "examples/compare-read.rs" >=20 > [[example]] > name =3D "pxarcmd" > @@ -47,6 +50,14 @@ siphasher =3D "0.3" >=20 > tokio =3D { version =3D "1.0", optional =3D true, default-features =3D f= alse } >=20 > +[dev-dependencies] > +anyhow =3D "1.0" > +tokio =3D { version =3D "1.0", default-features =3D false, features =3D = [ > + "fs", > + "macros", > + "rt-multi-thread" > +] } > + > [target.'cfg(target_os =3D "linux")'.dependencies] > libc =3D "0.2" >=20 > @@ -57,11 +68,4 @@ tokio-fs =3D [ "tokio-io", "tokio/fs" ] >=20 > full =3D [ "tokio-fs"] >=20 > -async-example =3D [ > - "tokio-io", > - "tokio-fs", > - "tokio/rt-multi-thread", > - "tokio/macros", > -] > - > test-harness =3D [] > diff --git a/examples/compare-read.rs b/examples/compare-read.rs > new file mode 100644 > index 0000000..c908077 > --- /dev/null > +++ b/examples/compare-read.rs > @@ -0,0 +1,150 @@ > +//! # Compare Read Speeds of Accessors and Decoders > +//! > +//! This example is used to compare read speeds between: > +//! > +//! * [`aio::Accessor`][pxar::accessor::aio::Accessor] > +//! * [`sync::Accessor`][pxar::accessor::sync::Accessor] > +//! * [`aio::Decoder`][pxar::decoder::aio::Decoder] > +//! * [`sync::Decoder`][pxar::decoder::sync::Decoder] > +//! > +//! ## Usage > +//! > +//! You may run this example directly on a PXAR archive: > +//! > +//! ```bash > +//! cargo run -q --example compare-read [FILE_PATH] > +//! cargo run -q --release --example compare-read [FILE_PATH] > +//! ``` > + > +use std::ffi::OsStr; > +use std::future::Future; > +use std::time::Duration; > + > +use anyhow::{Context, Result}; > +use pxar::accessor::aio::Accessor as AioAccessor; > +use pxar::accessor::sync::Accessor as SyncAccessor; > +use pxar::decoder::aio::Decoder as AioDecoder; > +use pxar::decoder::sync::Decoder as SyncDecoder; > + > +async fn read_with_decoder(file: &OsStr) -> Result<()> { > + let file =3D tokio::fs::File::open(file) > + .await > + .context("failed to open file")?; > + > + let mut reader =3D AioDecoder::from_tokio(file) > + .await > + .context("failed to open pxar archive contents")?; > + > + let mut entries =3D vec![]; > + > + while let Some(entry) =3D reader.next().await { > + let entry =3D entry.context("failed to parse entry")?; > + > + entries.push(entry); > + } > + > + Ok(()) > +} > + > +async fn read_with_decoder_sync(file: &OsStr) -> Result<()> { > + let file =3D std::fs::File::open(file).context("failed to open file"= )?; > + > + let reader =3D SyncDecoder::from_std(file).context("failed to open p= xar archive contents")?; > + > + let mut entries =3D vec![]; > + > + for entry in reader { > + let entry =3D entry.context("failed to parse entry")?; > + entries.push(entry); > + } > + > + Ok(()) > +} > + > +async fn read_with_accessor(file: &OsStr) -> Result<()> { > + let accessor =3D AioAccessor::open(file) > + .await > + .context("failed to open pxar archive contents")?; > + > + let dir =3D accessor.open_root_ref().await?; > + let mut decode_full =3D dir.decode_full().await?; > + > + let mut entries =3D vec![]; > + > + while let Some(entry) =3D decode_full.next().await { > + let entry =3D entry.context("failed to parse entry")?; > + > + entries.push(entry); > + } > + > + Ok(()) > +} > + > +async fn read_with_accessor_sync(file: &OsStr) -> Result<()> { > + let accessor =3D SyncAccessor::open(file).context("failed to open px= ar archive contents")?; > + > + let dir =3D accessor.open_root_ref()?; > + let decode_full =3D dir.decode_full()?; > + > + let mut entries =3D vec![]; > + > + for entry in decode_full { > + let entry =3D entry.context("failed to parse entry")?; > + > + entries.push(entry); > + } > + > + Ok(()) > +} > + > +async fn measure_duration(future: F) -> (R, Duration) > +where > + F: Future, > + R: Send + 'static, > +{ > + use std::time::Instant; > + let start =3D Instant::now(); > + let return_value =3D future.await; > + let elapsed =3D start.elapsed(); > + > + (return_value, elapsed) > +} > + > +async fn run_reads(file: &OsStr) -> Result<()> { > + let (result, elapsed) =3D measure_duration(read_with_decoder(&file))= .await; > + println!("With aio::Decoder: {result:?} (elapsed: {elapsed:#?})"); > + > + let (result, elapsed) =3D measure_duration(read_with_decoder_sync(&f= ile)).await; > + println!("With sync::Decoder: {result:?} (elapsed: {elapsed:#?})"); > + > + let (result, elapsed) =3D measure_duration(read_with_accessor(&file)= ).await; > + println!("With aio::Accessor: {result:?} (elapsed: {elapsed:#?})"); > + > + let (result, elapsed) =3D measure_duration(read_with_accessor_sync(&= file)).await; > + println!("With sync::Accessor: {result:?} (elapsed: {elapsed:#?})"); > + > + Ok(()) > +} > + > +#[tokio::main] > +async fn main() -> Result<()> { > + let mode =3D if cfg!(debug_assertions) { > + "debug" > + } else { > + "release" > + }; > + > + println!("PXAR Read Performance Comparison"); > + println!("Running in mode: {mode}\n"); > + > + let mut args =3D std::env::args_os().skip(1); > + > + let file =3D args.next().context("expected file name")?; > + println!("First pass:"); > + run_reads(&file).await?; > + > + println!("\nSecond pass:"); > + run_reads(&file).await?; > + > + Ok(()) > +} > -- > 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