Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
8f22bc0
harness: aqpbm-harness crate skeleton and the thread CPU clock stub
zzylol Nov 16, 2026
5366103
harness: failing tests for the aqpbm-harness core
zzylol Nov 16, 2026
19cba8a
harness: implement the aqpbm-harness core
zzylol Nov 16, 2026
e979cd3
harness: apply the independent-review fixes
zzylol Nov 16, 2026
8d3b78d
harness: failing tests for the final-review fixes
zzylol Nov 17, 2026
a4daa63
harness: apply the final-review fixes
zzylol Nov 17, 2026
b8555e2
refactor: move the harness into aqpbm-core
zzylol Nov 17, 2026
1785074
refactor: name the harness error-quantile module by what it holds
zzylol Nov 17, 2026
1bcb9f5
engines-external: failing tests for the plan-file reader and the Clic…
zzylol Nov 17, 2026
1e0b120
engines-external: apply the independent review of the tests
zzylol Nov 17, 2026
bc276e3
engines-external: read ASAPPlanner plan files and translate them to C…
zzylol Nov 17, 2026
6d7fba4
engines-external: apply the independent review of the implementation
zzylol Nov 17, 2026
92daa57
engines-external: failing tests for the review fixes
zzylol Nov 17, 2026
2d8cb72
engines-external: fix the review findings in the ClickHouse translator
zzylol Nov 17, 2026
ba57ecb
engines-external: apply the independent review of the fixes
zzylol Nov 17, 2026
2ed3d47
engines-external: cite ASAPPlanner main bc725bda8 for the fixtures an…
zzylol Nov 17, 2026
93ee4a0
harness: failing tests for the bench-external lanes, report and cgrou…
zzylol Nov 17, 2026
8180f8d
harness: bench-external lanes over one run directory, report, cgroup …
zzylol Nov 17, 2026
eddf25b
harness, cli: failing tests for the bench-external CLI, the server-co…
zzylol Nov 17, 2026
92c8532
harness, cli: approxbench bench-external and cgroup-agent; idle check…
zzylol Nov 17, 2026
dd6cb80
harness: apply the independent review of the bench-external slice
zzylol Nov 17, 2026
9a08147
harness: answers carry PromQL output labels; the server-cores idle ch…
zzylol Nov 17, 2026
8695c0d
harness: a lane refuses workload and variant names that cannot name a…
zzylol Nov 17, 2026
7c0d121
harness: rustfmt after the move into aqpbm-core
zzylol Nov 17, 2026
ec6e09d
Merge main into bench-external/run-slice
GordonYuanyc Nov 19, 2026
6bf050d
harness, cli: read a remote server's cgroup files over SSH; remove th…
GordonYuanyc Nov 19, 2026
4b3630e
harness, cli: name things by what they are: engine runs, run director…
GordonYuanyc Nov 19, 2026
8dabe25
harness: SSH reads: missing file by exit status, control socket in ~/…
GordonYuanyc Nov 19, 2026
a1609cc
harness: rename the names the review found left over
GordonYuanyc Nov 19, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 124 additions & 0 deletions aqpbm-cli/src/benchmark_external_cmd.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
//! `approxbench benchmark-external`: run one engine over a run directory, or join
//! every engine run's cells into the report.
//!
//! Example: `approxbench benchmark-external run --run-directory R --engine fake`, then
//! `approxbench benchmark-external report --run-directory R --truth fake/v1`.

use std::path::PathBuf;

use anyhow::{bail, Context, Result};
use aqpbm_core::harness::benchmark_external::{report, run_engine, write_report, EngineRunSetup};
use aqpbm_core::harness::engine::EngineUnderTest;
use aqpbm_core::harness::fake::FakeEngine;
use aqpbm_core::harness::protocol::{
load_probe_for, MeasurementClocks, OsCpuClock, ProcessCpuFiles, Protocol,
};
use aqpbm_core::harness::run_directory::RunDirectory;
use clap::{Parser, Subcommand};

/// The engines this binary can run.
pub const ENGINES: [&str; 1] = ["fake"];

#[derive(Parser, Debug)]
pub struct BenchmarkExternalArgs {
#[command(subcommand)]
pub command: BenchmarkExternalCmd,
}

#[derive(Subcommand, Debug)]
pub enum BenchmarkExternalCmd {
/// Run every (workload, variant) cell of the run directory on one engine.
Run(RunArgs),
/// Join every engine run's cells into summary.csv, summary.md and accuracy.csv.
Report(ReportArgs),
}

#[derive(Parser, Debug)]
pub struct RunArgs {
/// The run directory: workloads/, plans/<variant>/, results/.
#[arg(long)]
pub run_directory: PathBuf,
/// The engine: `fake` (the harness's own fake engine).
#[arg(long)]
pub engine: String,
/// Only these variants (repeatable); every variant under plans/ by default.
#[arg(long = "variant")]
pub variants: Vec<String>,
/// The core the harness pins each step to.
#[arg(long, default_value_t = 0)]
pub core: usize,
/// Runs discarded before measuring, per step.
#[arg(long, default_value_t = Protocol::default().warmup_runs)]
pub warmup: u32,
/// Runs measured per step; odd.
#[arg(long, default_value_t = Protocol::default().measured_runs)]
pub runs: u32,
/// A core busier than this fraction before a step refuses it.
#[arg(long, default_value_t = Protocol::default().max_core_busy_fraction)]
pub max_core_busy: f64,
}

#[derive(Parser, Debug)]
pub struct ReportArgs {
#[arg(long)]
pub run_directory: PathBuf,
/// The cells answers are compared with: `<engine>/<variant>`.
#[arg(long)]
pub truth: String,
}

pub fn run(args: BenchmarkExternalArgs) -> Result<()> {
match args.command {
BenchmarkExternalCmd::Run(args) => run_engine_cmd(args),
BenchmarkExternalCmd::Report(args) => report_cmd(args),
}
}

fn run_engine_cmd(args: RunArgs) -> Result<()> {
let engine: Box<dyn EngineUnderTest> = match args.engine.as_str() {
"fake" => Box::new(FakeEngine::default()),
other => bail!(
"unknown engine '{other}'; known engines: {}",
ENGINES.join(", ")
),
};
let run_directory = RunDirectory::open(&args.run_directory)?;
let protocol = Protocol {
warmup_runs: args.warmup,
measured_runs: args.runs,
max_core_busy_fraction: args.max_core_busy,
};
let clocks = MeasurementClocks::with_calling_thread(&OsCpuClock);
// The idle check watches the server's cores for an external server, the
// harness core for an in-process engine.
let mut probe = load_probe_for(&engine.cpu_accounting(), &ProcessCpuFiles::os())?;
let only = (!args.variants.is_empty()).then_some(args.variants.as_slice());
let cells = run_engine(
&run_directory,
engine.as_ref(),
only,
EngineRunSetup {
protocol: &protocol,
core: args.core,
probe: probe.as_mut(),
clocks: &clocks,
args: std::env::args().collect(),
},
)?;
for cell in cells {
println!("{} {} {:?}", cell.workload, cell.variant, cell.outcome);
}
Ok(())
}

fn report_cmd(args: ReportArgs) -> Result<()> {
let (engine, variant) = args
.truth
.split_once('/')
.context("--truth must be <engine>/<variant>")?;
let run_directory = RunDirectory::open(&args.run_directory)?;
let report = report(&run_directory, engine, variant)?;
write_report(&run_directory, &report)?;
print!("{}", report.summary_markdown());
Ok(())
}
3 changes: 3 additions & 0 deletions aqpbm-cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use clap::builder::TypedValueParser;
use clap::{Parser, Subcommand};

use crate::atomic_costs_cmd;
use crate::benchmark_external_cmd;
use crate::flatten_cmd;

#[derive(Parser, Debug)]
Expand Down Expand Up @@ -37,6 +38,8 @@ pub enum Cmd {
/// records that came from several invocations of the same cell rather
/// than one.
Flatten(flatten_cmd::FlattenArgs),
/// Run one engine of a comparison over a run directory, or report all engine runs.
BenchmarkExternal(benchmark_external_cmd::BenchmarkExternalArgs),
}

/// One target of the sketch bundle: one variant, one library, one construction
Expand Down
1 change: 1 addition & 0 deletions aqpbm-cli/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub mod atomic_costs;
pub mod atomic_costs_cmd;
pub mod benchmark_external_cmd;
pub mod cli;
pub mod external;
pub mod flatten_cmd;
Expand Down
3 changes: 2 additions & 1 deletion aqpbm-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ static GLOBAL: aqpbm_core::metrics::heap_track::TrackingAllocator<std::alloc::Sy

use anyhow::Result;
use aqpbm_cli::cli::{Cli, Cmd};
use aqpbm_cli::{atomic_costs_cmd, flatten_cmd, sketchbench};
use aqpbm_cli::{atomic_costs_cmd, benchmark_external_cmd, flatten_cmd, sketchbench};
use clap::Parser;

fn main() -> Result<()> {
Expand All @@ -31,5 +31,6 @@ fn main() -> Result<()> {
Cmd::Sketchbench(args) => sketchbench::run_sketchbench(args),
Cmd::AtomicCosts(args) => atomic_costs_cmd::run(args),
Cmd::Flatten(args) => flatten_cmd::run(args),
Cmd::BenchmarkExternal(args) => benchmark_external_cmd::run(args),
}
}
164 changes: 164 additions & 0 deletions aqpbm-cli/tests/benchmark_external_cli.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
//! `approxbench benchmark-external run` and `report` on the fake engine.

use std::path::{Path, PathBuf};
use std::process::Command;

use aqpbm_core::harness::data::DataRecord;
use aqpbm_core::harness::engine::{QueryLanguage, QueryText, WorkloadQuery, WorkloadSpec};
use aqpbm_core::harness::run_directory::RunDirectory;
use aqpbm_datagen::{DataDistribution, SeriesLabelSpec, TimeSeriesDescription, UniformParameter};

fn workload(name: &str) -> WorkloadSpec {
WorkloadSpec {
name: name.into(),
queries: vec![WorkloadQuery {
id: "sum".into(),
texts: vec![QueryText {
language: QueryLanguage::PromQl,
text: "sum_over_time(m[10s])".into(),
}],
window_ms: 10_000,
evaluation_interval_ms: 10_000,
}],
data: vec![DataRecord {
metric: "m".into(),
description: TimeSeriesDescription {
labels: vec![SeriesLabelSpec {
name: "s".into(),
cardinality: 2,
skewness: 0.0,
}],
series_num: 2,
start_ms: 0,
sample_interval_ms: 1_000,
duration_ms: 60_000,
value_distribution: DataDistribution::Uniform(UniformParameter {
lower_bound: 0.0,
upper_bound: 10.0,
seed: 0,
}),
counter: false,
seed: 1,
},
}],
}
}

fn write(path: &Path, text: &str) {
std::fs::create_dir_all(path.parent().unwrap()).unwrap();
std::fs::write(path, text).unwrap();
}

fn fixture(test: &str) -> PathBuf {
let root = std::env::temp_dir().join(format!(
"approxbench-benchmark-external-{}-{test}",
std::process::id()
));
let _ = std::fs::remove_dir_all(&root);
let run = RunDirectory::create_at(&root.join("run")).unwrap();
for name in ["w1", "w2"] {
write(
&run.path().join(format!("workloads/{name}.json")),
&serde_json::to_string(&workload(name)).unwrap(),
);
}
let plans = run.path().join("plans");
write(
&plans.join("v1/variant.json"),
r#"{"substitutions_allowed": false}"#,
);
write(&plans.join("v1/w1.plan.json"), "{}");
write(
&plans.join("v1/w2.no-plan.json"),
r#"{"reason": "ExcludedByDeployment"}"#,
);
write(
&plans.join("v2/variant.json"),
r#"{"substitutions_allowed": true}"#,
);
write(&plans.join("v2/w1.plan.json"), "{}");
write(&plans.join("v2/w2.plan.json"), "{}");
run.path().to_path_buf()
}

fn approxbench(args: &[&str]) -> std::process::Output {
Command::new(env!("CARGO_BIN_EXE_approxbench"))
.args(args)
.output()
.unwrap()
}

/// X1: a fake engine runs every cell, and the report has one row per cell.
#[test]
fn a_fake_engine_runs_and_reports() {
let run = fixture("x1");
let run_directory = run.to_str().unwrap();
let out = approxbench(&[
"benchmark-external",
"run",
"--run-directory",
run_directory,
"--engine",
"fake",
"--warmup",
"0",
"--runs",
"1",
"--max-core-busy",
"1.0",
]);
assert!(
out.status.success(),
"{}",
String::from_utf8_lossy(&out.stderr)
);
let out = approxbench(&[
"benchmark-external",
"report",
"--run-directory",
run_directory,
"--truth",
"fake/v2",
]);
assert!(
out.status.success(),
"{}",
String::from_utf8_lossy(&out.stderr)
);
let summary = std::fs::read_to_string(run.join("summary.csv")).unwrap();
assert_eq!(summary.lines().count(), 5, "{summary}");
assert!(
summary
.lines()
.any(|line| line.starts_with("w1,fake,v1,ok,thread,")),
"{summary}"
);
assert!(
summary
.lines()
.any(|line| line.starts_with("w2,fake,v1,no plan: ExcludedByDeployment")),
"{summary}"
);
let _ = std::fs::remove_dir_all(run.parent().unwrap());
}

/// X2: an unknown engine names the known ones.
#[test]
fn an_unknown_engine_names_the_known_engines() {
let run = fixture("x2");
let out = approxbench(&[
"benchmark-external",
"run",
"--run-directory",
run.to_str().unwrap(),
"--engine",
"clickhouse",
]);
assert!(!out.status.success());
let stderr = String::from_utf8_lossy(&out.stderr);
assert!(
stderr.contains("clickhouse") && stderr.contains("fake"),
"{stderr}"
);
let _ = std::fs::remove_dir_all(run.parent().unwrap());
}
4 changes: 2 additions & 2 deletions aqpbm-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ tikv-jemalloc-ctl = { workspace = true, optional = true }
[target.'cfg(unix)'.dependencies]
libc.workspace = true

# Runs on the process's main thread (no libtest harness), where a pinned
# thread is also the thread whose affinity `getpid()` names.
# Runs on the process's main thread (no libtest harness), so the thread the
# test pins is the one whose affinity it then reads.
[[test]]
name = "harness_pin_main_thread"
harness = false
Loading
Loading