From e6a31fe140966a9f8ab17121d16ecfd04a45fdfa Mon Sep 17 00:00:00 2001 From: Raphael Druon Date: Thu, 8 Aug 2024 05:00:06 -0600 Subject: [PATCH] New benchmark --- Cargo.lock | 26 ++++++++- lustre-collector/Cargo.toml | 17 ------ lustre-collector/benches/jobstats_fast.rs | 49 ---------------- lustre-collector/benches/jobstats_slow.rs | 52 ----------------- lustrefs-exporter/Cargo.toml | 13 +++++ lustrefs-exporter/benches/jobstats.rs | 69 +++++++++++++++++++++++ 6 files changed, 107 insertions(+), 119 deletions(-) delete mode 100644 lustre-collector/benches/jobstats_fast.rs delete mode 100644 lustre-collector/benches/jobstats_slow.rs create mode 100644 lustrefs-exporter/benches/jobstats.rs diff --git a/Cargo.lock b/Cargo.lock index 190bd0f..3577416 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -372,6 +372,7 @@ dependencies = [ "ciborium", "clap", "criterion-plot", + "futures", "is-terminal", "itertools", "num-traits", @@ -384,6 +385,7 @@ dependencies = [ "serde_derive", "serde_json", "tinytemplate", + "tokio", "walkdir", ] @@ -484,6 +486,20 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + [[package]] name = "futures-channel" version = "0.3.30" @@ -491,6 +507,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" dependencies = [ "futures-core", + "futures-sink", ] [[package]] @@ -499,6 +516,12 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + [[package]] name = "futures-sink" version = "0.3.30" @@ -518,6 +541,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" dependencies = [ "futures-core", + "futures-sink", "futures-task", "pin-project-lite", "pin-utils", @@ -807,7 +831,6 @@ version = "0.9.0" dependencies = [ "clap", "combine", - "criterion", "include_dir", "insta", "serde", @@ -827,6 +850,7 @@ dependencies = [ "combine", "compact_str", "const_format", + "criterion", "include_dir", "insta", "lustre_collector", diff --git a/lustre-collector/Cargo.toml b/lustre-collector/Cargo.toml index fe56511..0c228f8 100644 --- a/lustre-collector/Cargo.toml +++ b/lustre-collector/Cargo.toml @@ -19,20 +19,3 @@ tracing.workspace = true [dev-dependencies] include_dir.workspace = true insta.workspace = true -criterion = { version = "0.5", features = ["html_reports"] } - -[lib] -bench = false - -[[bin]] -name = "lustre_collector" -path = "src/main.rs" -bench = false - -[[bench]] -name = "jobstats_slow" -harness = false - -[[bench]] -name = "jobstats_fast" -harness = false diff --git a/lustre-collector/benches/jobstats_fast.rs b/lustre-collector/benches/jobstats_fast.rs deleted file mode 100644 index 2465fa8..0000000 --- a/lustre-collector/benches/jobstats_fast.rs +++ /dev/null @@ -1,49 +0,0 @@ -use criterion::{black_box, criterion_group, criterion_main, Criterion}; -use lustre_collector::{parse_lctl_output, Record}; - -fn test_data(repeat: usize) -> String { - let job = r#" - - job_id: "SLURM_JOB_machine184_74186:0:ma" - snapshot_time: 1720516680 - read_bytes: { samples: 0, unit: bytes, min: 0, max: 0, sum: 0, sumsq: 0 } - write_bytes: { samples: 52, unit: bytes, min: 4096, max: 475136, sum: 5468160, sumsq: 1071040692224 } - read: { samples: 0, unit: usecs, min: 0, max: 0, sum: 0, sumsq: 0 } - write: { samples: 52, unit: usecs, min: 12, max: 40081, sum: 692342, sumsq: 17432258604 } - getattr: { samples: 0, unit: usecs, min: 0, max: 0, sum: 0, sumsq: 0 } - setattr: { samples: 0, unit: usecs, min: 0, max: 0, sum: 0, sumsq: 0 } - punch: { samples: 0, unit: usecs, min: 0, max: 0, sum: 0, sumsq: 0 } - sync: { samples: 0, unit: usecs, min: 0, max: 0, sum: 0, sumsq: 0 } - destroy: { samples: 0, unit: usecs, min: 0, max: 0, sum: 0, sumsq: 0 } - create: { samples: 0, unit: usecs, min: 0, max: 0, sum: 0, sumsq: 0 } - statfs: { samples: 0, unit: usecs, min: 0, max: 0, sum: 0, sumsq: 0 } - get_info: { samples: 0, unit: usecs, min: 0, max: 0, sum: 0, sumsq: 0 } - set_info: { samples: 0, unit: usecs, min: 0, max: 0, sum: 0, sumsq: 0 } - quotactl: { samples: 0, unit: usecs, min: 0, max: 0, sum: 0, sumsq: 0 } - prealloc: { samples: 0, unit: usecs, min: 0, max: 0, sum: 0, sumsq: 0 }"#; - let lctl_output = r#"obdfilter.ds002-OST0000.job_stats= -job_stats:"#; - - let input = format!("{lctl_output}{}", job.to_string().repeat(repeat)); - - input -} - -fn parse_jobstats(repeat: usize) -> Vec { - let input = test_data(repeat); - parse_lctl_output(input.as_bytes()).unwrap() -} - -fn criterion_benchmark_fast(c: &mut Criterion) { - c.bench_function("jobstats 100", |b| { - b.iter(|| parse_jobstats(black_box(100))) - }); - c.bench_function("jobstats 1000", |b| { - b.iter(|| parse_jobstats(black_box(1000))) - }); -} -criterion_group! { - name = benches; - config = Criterion::default(); - targets = criterion_benchmark_fast -} -criterion_main!(benches); diff --git a/lustre-collector/benches/jobstats_slow.rs b/lustre-collector/benches/jobstats_slow.rs deleted file mode 100644 index d7ec1e0..0000000 --- a/lustre-collector/benches/jobstats_slow.rs +++ /dev/null @@ -1,52 +0,0 @@ -use std::time::Duration; - -use criterion::{black_box, criterion_group, criterion_main, Criterion}; -use lustre_collector::{parse_lctl_output, Record}; - -fn test_data(repeat: usize) -> String { - let job = r#" - - job_id: "SLURM_JOB_machine184_74186:0:ma" - snapshot_time: 1720516680 - read_bytes: { samples: 0, unit: bytes, min: 0, max: 0, sum: 0, sumsq: 0 } - write_bytes: { samples: 52, unit: bytes, min: 4096, max: 475136, sum: 5468160, sumsq: 1071040692224 } - read: { samples: 0, unit: usecs, min: 0, max: 0, sum: 0, sumsq: 0 } - write: { samples: 52, unit: usecs, min: 12, max: 40081, sum: 692342, sumsq: 17432258604 } - getattr: { samples: 0, unit: usecs, min: 0, max: 0, sum: 0, sumsq: 0 } - setattr: { samples: 0, unit: usecs, min: 0, max: 0, sum: 0, sumsq: 0 } - punch: { samples: 0, unit: usecs, min: 0, max: 0, sum: 0, sumsq: 0 } - sync: { samples: 0, unit: usecs, min: 0, max: 0, sum: 0, sumsq: 0 } - destroy: { samples: 0, unit: usecs, min: 0, max: 0, sum: 0, sumsq: 0 } - create: { samples: 0, unit: usecs, min: 0, max: 0, sum: 0, sumsq: 0 } - statfs: { samples: 0, unit: usecs, min: 0, max: 0, sum: 0, sumsq: 0 } - get_info: { samples: 0, unit: usecs, min: 0, max: 0, sum: 0, sumsq: 0 } - set_info: { samples: 0, unit: usecs, min: 0, max: 0, sum: 0, sumsq: 0 } - quotactl: { samples: 0, unit: usecs, min: 0, max: 0, sum: 0, sumsq: 0 } - prealloc: { samples: 0, unit: usecs, min: 0, max: 0, sum: 0, sumsq: 0 }"#; - let lctl_output = r#"obdfilter.ds002-OST0000.job_stats= -job_stats:"#; - - let input = format!("{lctl_output}{}", job.to_string().repeat(repeat)); - - input -} - -fn parse_jobstats(repeat: usize) -> Vec { - let input = test_data(repeat); - parse_lctl_output(input.as_bytes()).unwrap() -} - -fn criterion_benchmark_slow(c: &mut Criterion) { - c.bench_function("jobstats 10000", |b| { - b.iter(|| parse_jobstats(black_box(10000))) - }); - c.bench_function("jobstats 100000", |b| { - b.iter(|| parse_jobstats(black_box(100000))) - }); -} - -criterion_group! { - name = benches; - config = Criterion::default().sample_size(10).measurement_time(Duration::from_secs(600)); - targets = criterion_benchmark_slow -} -criterion_main!(benches); diff --git a/lustrefs-exporter/Cargo.toml b/lustrefs-exporter/Cargo.toml index 06bf942..1dfeb4a 100644 --- a/lustrefs-exporter/Cargo.toml +++ b/lustrefs-exporter/Cargo.toml @@ -31,3 +31,16 @@ const_format = "0.2.32" include_dir.workspace = true insta.workspace = true serde_json = "1" +criterion = { version = "0.5", features = ["html_reports", "async_tokio"] } + +[lib] +bench = false + +[[bin]] +name = "lustrefs-exporter" +path = "src/main.rs" +bench = false + +[[bench]] +name = "jobstats" +harness = false diff --git a/lustrefs-exporter/benches/jobstats.rs b/lustrefs-exporter/benches/jobstats.rs new file mode 100644 index 0000000..486d67c --- /dev/null +++ b/lustrefs-exporter/benches/jobstats.rs @@ -0,0 +1,69 @@ +use std::io::BufReader; + +use const_format::{formatcp, str_repeat}; +use criterion::{black_box, criterion_group, criterion_main, Criterion}; +use lustrefs_exporter::jobstats::jobstats_stream; + +const JOBSTAT_JOB: &str = r#" +- job_id: "FAKE_JOB" + snapshot_time: 1720516680 + read_bytes: { samples: 0, unit: bytes, min: 0, max: 0, sum: 0, sumsq: 0 } + write_bytes: { samples: 52, unit: bytes, min: 4096, max: 475136, sum: 5468160, sumsq: 1071040692224 } + read: { samples: 0, unit: usecs, min: 0, max: 0, sum: 0, sumsq: 0 } + write: { samples: 52, unit: usecs, min: 12, max: 40081, sum: 692342, sumsq: 17432258604 } + getattr: { samples: 0, unit: usecs, min: 0, max: 0, sum: 0, sumsq: 0 } + setattr: { samples: 0, unit: usecs, min: 0, max: 0, sum: 0, sumsq: 0 } + punch: { samples: 0, unit: usecs, min: 0, max: 0, sum: 0, sumsq: 0 } + sync: { samples: 0, unit: usecs, min: 0, max: 0, sum: 0, sumsq: 0 } + destroy: { samples: 0, unit: usecs, min: 0, max: 0, sum: 0, sumsq: 0 } + create: { samples: 0, unit: usecs, min: 0, max: 0, sum: 0, sumsq: 0 } + statfs: { samples: 0, unit: usecs, min: 0, max: 0, sum: 0, sumsq: 0 } + get_info: { samples: 0, unit: usecs, min: 0, max: 0, sum: 0, sumsq: 0 } + set_info: { samples: 0, unit: usecs, min: 0, max: 0, sum: 0, sumsq: 0 } + quotactl: { samples: 0, unit: usecs, min: 0, max: 0, sum: 0, sumsq: 0 } + prealloc: { samples: 0, unit: usecs, min: 0, max: 0, sum: 0, sumsq: 0 }"#; + +#[allow(long_running_const_eval)] +const INPUT_100_JOBS: &str = formatcp!( + r#"obdfilter.ds002-OST0000.job_stats= +job_stats:{}"#, + str_repeat!(JOBSTAT_JOB, 100) +); + +#[allow(long_running_const_eval)] +const INPUT_1000_JOBS: &str = formatcp!( + r#"obdfilter.ds002-OST0000.job_stats= +job_stats:{}"#, + str_repeat!(JOBSTAT_JOB, 1000) +); + +async fn parse_synthetic_yaml(input: &'static str, len: usize) { + let f = BufReader::with_capacity(128 * 1_024, input.as_bytes()); + + let (fut, mut rx) = jobstats_stream(f); + + let mut cnt = 0; + + while rx.recv().await.is_some() { + cnt += 1; + } + + fut.await.unwrap(); +} + +fn criterion_benchmark_fast(c: &mut Criterion) { + c.bench_function("jobstats 100", |b| { + b.to_async(tokio::runtime::Builder::new_multi_thread().build().unwrap()) + .iter(|| black_box(parse_synthetic_yaml(INPUT_100_JOBS, 100))) + }); + c.bench_function("jobstats 1000", |b| { + b.to_async(tokio::runtime::Builder::new_multi_thread().build().unwrap()) + .iter(|| black_box(parse_synthetic_yaml(INPUT_1000_JOBS, 1000))) + }); +} +criterion_group! { + name = benches; + config = Criterion::default(); + targets = criterion_benchmark_fast +} +criterion_main!(benches);