From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 566141FF389 for ; Tue, 7 May 2024 15:45:52 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 28E14F412; Tue, 7 May 2024 15:45:57 +0200 (CEST) From: Dominik Csapak To: pbs-devel@lists.proxmox.com Date: Tue, 7 May 2024 15:45:53 +0200 Message-Id: <20240507134553.3233550-2-d.csapak@proxmox.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240507134553.3233550-1-d.csapak@proxmox.com> References: <20240507134553.3233550-1-d.csapak@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.016 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 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [tape-write-benchmark.rs] Subject: [pbs-devel] [PATCH proxmox-backup 2/2] examples: add tape write benchmark 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: , Reply-To: Proxmox Backup Server development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pbs-devel-bounces@lists.proxmox.com Sender: "pbs-devel" A small example that simply writes pseudo-random chunks to a drive. This is useful to benchmark throughput on tape drives. The output and behavior is similar to what the pool writer does, but without writing multiple files, committing or loading data from disk. Signed-off-by: Dominik Csapak --- examples/tape-write-benchmark.rs | 91 ++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 examples/tape-write-benchmark.rs diff --git a/examples/tape-write-benchmark.rs b/examples/tape-write-benchmark.rs new file mode 100644 index 000000000..d5686e65a --- /dev/null +++ b/examples/tape-write-benchmark.rs @@ -0,0 +1,91 @@ +use std::{ + fs::File, + io::Read, + time::{Duration, SystemTime}, +}; + +use anyhow::{format_err, Error}; +use pbs_tape::TapeWrite; +use proxmox_backup::tape::drive::{LtoTapeHandle, TapeDriver}; + +const URANDOM_PATH: &str = "/dev/urandom"; +const CHUNK_SIZE: usize = 4 * 1024 * 1024; // 4 MiB +const LOG_LIMIT: usize = 4 * 1024 * 1024 * 1024; // 4 GiB + +fn write_chunks<'a>( + mut writer: Box, + blob_size: usize, + max_size: usize, + max_time: Duration, +) -> Result<(), Error> { + // prepare chunks in memory + + let mut blob: Vec = vec![0u8; blob_size]; + + let mut file = File::open(URANDOM_PATH)?; + file.read_exact(&mut blob[..])?; + + let start_time = SystemTime::now(); + loop { + let iteration_time = SystemTime::now(); + let mut count = 0; + let mut bytes_written = 0; + let mut idx = 0; + let mut incr_count = 0; + loop { + if writer.write_all(&blob)? { + eprintln!("LEOM reached"); + break; + } + + // modifying chunks a bit to mitigate compression/deduplication + blob[idx] = blob[idx].wrapping_add(1); + incr_count += 1; + if incr_count >= 256 { + incr_count = 0; + idx += 1; + } + count += 1; + bytes_written += blob_size; + + if bytes_written > max_size { + break; + } + } + + let elapsed = iteration_time.elapsed()?.as_secs_f64(); + let elapsed_total = start_time.elapsed()?; + eprintln!( + "{:.2}s: wrote {} chunks ({:.2} MB at {:.2} MB/s, average: {:.2} MB/s)", + elapsed_total.as_secs_f64(), + count, + bytes_written as f64 / 1_000_000.0, + (bytes_written as f64) / (1_000_000.0 * elapsed), + (writer.bytes_written() as f64) / (1_000_000.0 * elapsed_total.as_secs_f64()), + ); + + if elapsed_total > max_time { + break; + } + } + + Ok(()) +} +fn main() -> Result<(), Error> { + let mut args = std::env::args_os(); + args.next(); // binary name + let path = args.next().expect("no path to tape device given"); + let file = File::open(path).map_err(|err| format_err!("could not open tape device: {err}"))?; + let mut drive = LtoTapeHandle::new(file) + .map_err(|err| format_err!("error creating drive handle: {err}"))?; + write_chunks( + drive + .write_file() + .map_err(|err| format_err!("error starting file write: {err}"))?, + CHUNK_SIZE, + LOG_LIMIT, + Duration::new(60 * 20, 0), + ) + .map_err(|err| format_err!("error writing data to tape: {err}"))?; + Ok(()) +} -- 2.39.2 _______________________________________________ pbs-devel mailing list pbs-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel