Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion aqpbm-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ name = "approxbench"
path = "src/main.rs"

[features]
default = ["heap-jemalloc"]
default = ["heap-jemalloc", "heap-track"]
# When on, approxbench links jemalloc as its global allocator and
# sketch-bench samples `tikv-jemalloc-ctl::stats::allocated` into
# `bench.heap_allocated_kb`. Turn off with `--no-default-features`
Expand Down
3 changes: 3 additions & 0 deletions aqpbm-cli/src/atomic_costs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,9 @@ mod tests {
memory_bytes: Some(12_288),
heap_bytes_net: None,
heap_bytes_peak: None,
core: None,
core_busy_max: None,
marks: Vec::new(),
insert: InsertMetrics {
throughput_items_per_sec: Some(stats(1_000_000.0)),
wall_time_ms: Some(stats(1000.0)),
Expand Down
13 changes: 13 additions & 0 deletions aqpbm-cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,19 @@ pub struct SketchbenchArgs {
/// cache measure the wrong thing.
#[arg(long, default_value_t = 3, help_heading = "Repetition")]
pub warmup_runs: usize,
#[arg(
long,
help_heading = "Repetition",
help = "Pin the measuring thread to this core and check the core is idle around every run; omitted, or with --workers above 1: not pinned and not checked, and each record says so"
)]
pub core: Option<usize>,
#[arg(
long,
default_value_t = aqpbm_core::DEFAULT_MAX_CORE_BUSY_FRACTION,
help_heading = "Repetition",
help = "A core busier than this fraction before a run refuses it; after a run, marks it"
)]
pub max_core_busy: f64,
/// Re-execute the whole invocation in this many separate processes and
/// report the 95% CI over their means. The only setting that makes `ci95`
/// appear. At 1 no interval is claimed. Costs R times the wall clock.
Expand Down
4 changes: 4 additions & 0 deletions aqpbm-cli/src/repeat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,10 @@ mod tests {
merge_supported: Some(true),
trial: None,
trial_mode: None,
core: Some(3),
core_busy_before_max: Some(0.01),
core_busy_after_max: Some(0.02),
marks: Vec::new(),
});
rec
}
Expand Down
10 changes: 9 additions & 1 deletion aqpbm-cli/src/sketchbench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,8 +420,16 @@ pub fn run_sketchbench(args: SketchbenchArgs) -> Result<()> {
// Exactly this measurement's recorders, plus whatever rides along.
// Arming the rest would build a histogram nothing writes to.
metrics: metric.bit() | secondary,
core: args.core.filter(|_| args.workers <= 1),
max_core_busy_fraction: args.max_core_busy,
};
let runs = aqpbm_core::measure(&cfg, body);
let mut runs = aqpbm_core::measure(&cfg, body)?;
if args.workers > 1 {
for run in &mut runs {
run.heap_bytes_net = None;
run.heap_bytes_peak = None;
}
}
let mut report = BenchReport::from_runs(
variant.as_str(),
library.as_str(),
Expand Down
55 changes: 55 additions & 0 deletions aqpbm-cli/tests/measured_heap.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
use std::process::Command;

fn insert_record(variant: &str, library: &str, config: &str) -> serde_json::Value {
let out = Command::new(env!("CARGO_BIN_EXE_approxbench"))
.args(["sketchbench", "--variant", variant, "--library", library])
.args(["--config", config])
.args(["--operations", "insert", "--metrics", "throughput,memory"])
.args(["--runs", "3", "--warmup-runs", "1"])
.args([
"--dataset",
"zipf",
"--zipf-s",
"1.1",
"--cardinality",
"10000",
])
.args(["--dtype", "i64", "--size", "100000", "--seed", "7"])
.env("BENCH_WARMUP_SECS", "0")
.output()
.expect("approxbench runs");
assert!(
out.status.success(),
"{}",
String::from_utf8_lossy(&out.stderr)
);
let stdout = String::from_utf8(out.stdout).expect("utf-8");
let last = stdout.lines().last().expect("one record");
serde_json::from_str(last).expect("a JSON record")
}

#[cfg(feature = "heap-track")]
#[test]
fn a_sketch_built_before_the_clock_starts_is_in_the_measured_heap() {
let record = insert_record("hyperloglog", "asap_sketchlib", "lg_k=14");
let bench = &record["bench"];
let declared = bench["memory_bytes"].as_u64().expect("memory_bytes");
let measured = bench["heap_bytes_peak"].as_u64().expect("heap_bytes_peak");
assert!(
measured >= declared && measured < declared + 1024,
"declared {declared}, measured {measured}"
);
}

#[cfg(feature = "heap-track")]
#[test]
fn a_row_that_allocates_while_it_inserts_is_in_the_measured_heap_once() {
let record = insert_record("hyperloglog", "polars", "lg_k=14");
let bench = &record["bench"];
let declared = bench["memory_bytes"].as_u64().expect("memory_bytes");
let measured = bench["heap_bytes_peak"].as_u64().expect("heap_bytes_peak");
assert!(
measured >= declared && measured < declared + 1024,
"declared {declared}, measured {measured}"
);
}
21 changes: 21 additions & 0 deletions aqpbm-core/schema/merged_record.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@
"description": "Flattened form of the [`Record`]s that share one (sketch, impl,\nsketch_config, dataset) identity: one row per invocation, where the record\nstream writes one per measurement. Built by `aqpbm-cli`'s `flatten_record`.\nLives beside [`Record`] because it is a JSONL wire shape, not CLI logic.",
"type": "object",
"properties": {
"core": {
"type": [
"integer",
"null"
],
"format": "uint",
"minimum": 0
},
"core_busy_max": {
"type": [
"number",
"null"
],
"format": "double"
},
"heap_bytes_net": {
"description": "Net bytes the tracking allocator attributes to this sketch's lifetime —\n**measured**, where [`Self::memory_bytes`] is a self-reported formula.\nIts own field, so a gap between the two stays visible. Needs `heap-track`.",
"type": [
Expand Down Expand Up @@ -91,6 +106,12 @@
"language": {
"$ref": "#/$defs/Language"
},
"marks": {
"type": "array",
"items": {
"type": "string"
}
},
"memory_bytes": {
"type": [
"integer",
Expand Down
14 changes: 14 additions & 0 deletions aqpbm-core/src/benchmark_result/bench_report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,20 @@ impl BenchReport {
bench.heap_bytes_net = mem.heap_bytes_net;
bench.heap_bytes_peak = mem.heap_bytes_peak;
bench.memory_bytes = fold::memory_bytes(&runs);
bench.core = runs.iter().find_map(|r| r.core);
bench.core_busy_before_max = runs
.iter()
.filter_map(|r| r.core_busy_before)
.max_by(f64::total_cmp);
bench.core_busy_after_max = runs
.iter()
.filter_map(|r| r.core_busy_after)
.max_by(f64::total_cmp);
for mark in runs.iter().flat_map(|r| &r.marks) {
if !bench.marks.contains(mark) {
bench.marks.push(mark.clone());
}
}

Self {
sketch: sketch.into(),
Expand Down
22 changes: 22 additions & 0 deletions aqpbm-core/src/benchmark_result/flatten_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ pub fn flatten_record(records: &[Record]) -> Result<MergedRecord, String> {
memory_bytes: None,
heap_bytes_net: None,
heap_bytes_peak: None,
core: None,
core_busy_max: None,
marks: Vec::new(),
insert: InsertMetrics::default(),
query: QueryMetrics::default(),
merge: MergeMetrics::default(),
Expand Down Expand Up @@ -91,8 +94,27 @@ pub fn flatten_record(records: &[Record]) -> Result<MergedRecord, String> {
merge_supported,
trial,
trial_mode,
core,
core_busy_before_max,
core_busy_after_max,
marks,
} = bench;

if let Some(core) = core {
out.core.get_or_insert(*core);
}
for busy in [core_busy_before_max, core_busy_after_max]
.into_iter()
.flatten()
{
out.core_busy_max = Some(out.core_busy_max.map_or(*busy, |max| max.max(*busy)));
}
for mark in marks {
if !out.marks.contains(mark) {
out.marks.push(mark.clone());
}
}

// A sketch has one size however many measurements took it, so the
// first value wins and none is favoured. `heap_bytes_net` stays
// separate from `memory_bytes`: see the field doc on
Expand Down
17 changes: 17 additions & 0 deletions aqpbm-core/src/benchmark_result/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,14 @@ pub struct BenchSection {
pub trial: Option<u64>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub trial_mode: Option<TrialMode>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub core: Option<usize>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub core_busy_before_max: Option<f64>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub core_busy_after_max: Option<f64>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub marks: Vec<String>,
}

/// Aggregate across N samples: mean / stddev / optional 95% CI, plus the raw
Expand Down Expand Up @@ -317,6 +325,12 @@ pub struct MergedRecord {
pub heap_bytes_net: Option<u64>,
/// High-water mark of the same counter across construction and insert.
pub heap_bytes_peak: Option<u64>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub core: Option<usize>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub core_busy_max: Option<f64>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub marks: Vec<String>,

// One slot per operation, and within a slot one field per metric. A
// measurement is named by both, so a flattened row that named only one of
Expand Down Expand Up @@ -503,6 +517,9 @@ pub fn merged_record_schema_json() -> String {
memory_bytes: None,
heap_bytes_net: None,
heap_bytes_peak: None,
core: None,
core_busy_max: None,
marks: Vec::new(),
insert: InsertMetrics::default(),
query: QueryMetrics::default(),
merge: MergeMetrics::default(),
Expand Down
Loading
Loading