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
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ approxbench: hydra-cms/lib config={"cell_cols":1024,"cell_rows":3,"cols":1024,"r
]
},
"merge_shards": 8,
"merge_split": "contiguous",
"merge_supported": true,
"merge_cpu_time_ms": {
"user_ms": {
Expand Down Expand Up @@ -447,6 +448,20 @@ approxbench: hydra-cms/lib config={"cell_cols":1024,"cell_rows":3,"cols":1024,"r
`--spec configs/datagen/hydra_columns.yaml` is how user can define the synthetic table for insertion.
The file can be found [under configs directory](./configs/datagen/hydra_columns.yaml).

**`--merge-shards`**: how many shards `merge` folds: the stream is split that
many ways, one sketch is fed per shard, and the sketches are folded into one.

**`--merge-split`**: how the stream is split into those shards. `contiguous`
(the default) cuts it into consecutive stretches; `interleaved` deals it
round-robin by record, so each shard is a sample of the whole stream. The
round-robin runs over the contiguous split's shard sizes (`ceil(N/k)` each,
the last one short), skipping a shard once it is full. So when `k` divides
`N`, shard 0 gets records `0, k, 2k, ...`; with a short last shard the
pattern shifts once that shard fills (N = 10, k = 4: shard 0 gets `0, 4, 7`).
The record's `merge_split` says which split ran. CMS, CountSketch and HLL cells (and their Hydra grids) merge
exactly, so they answer identically under both; KLL and UnivMon merges are
lossy and can differ.

**`--flat`**: flatten record such that output data of multiple experiments is flatten into one json file.

**`--group-columns`** (Hydra rows only): which label columns the subpopulation is taken over, as comma-separated indices into the columns before the value column, e.g. `1` or `0,1`; default `0`.
Expand Down
14 changes: 14 additions & 0 deletions aqpbm-cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
//! `main.rs`. Option help and grouping track `docs/aqpbm-cli-reference.md`, which
//! `scripts/dump_cli_reference.sh` diffs the built binary against.

use aqpbm_core::MergeSplit;
use clap::builder::TypedValueParser;
use clap::{Parser, Subcommand};

use crate::atomic_costs_cmd;
Expand Down Expand Up @@ -234,6 +236,18 @@ pub struct SketchbenchArgs {
/// merge exactly, so a gap is a defect; for KLL it is the result.
#[arg(long, default_value_t = 2, help_heading = "Measurement content")]
pub merge_shards: usize,
/// How the merge operation splits the stream into its shards: `contiguous`
/// cuts it into stretches, `interleaved` deals it round-robin by record, so
/// each shard is a sample of the whole stream. The shard sizes are the same
/// either way.
#[arg(
long,
default_value = "contiguous",
value_parser = clap::builder::PossibleValuesParser::new(["contiguous", "interleaved"])
.try_map(|s| s.parse::<MergeSplit>()),
help_heading = "Measurement content"
)]
pub merge_split: MergeSplit,
/// Which label columns the `hydra-*` rows group by, comma-separated
/// indices into the columns before the value column: any non-empty subset
/// (`0`, `1`, `0,1`). The grid stores every subset, so this picks the one
Expand Down
36 changes: 34 additions & 2 deletions aqpbm-cli/src/flatten_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
//! named by both. Grouping records by identity is the caller's job.

use aqpbm_core::{
BenchSection, InsertMetrics, MergeMetrics, MergedRecord, PrepareMetrics, QueryMetrics, Record,
BenchSection, InsertMetrics, MergeMetrics, MergeSplit, MergedRecord, PrepareMetrics,
QueryMetrics, Record,
};

/// Which slot a `Record` lands in, per its own `bench.operation` field. Every
Expand Down Expand Up @@ -84,6 +85,7 @@ pub fn flatten_record(records: &[Record]) -> Result<MergedRecord, String> {
accuracy,
merge_folds_per_sec,
merge_shards,
merge_split,
merge_supported,
} = bench;

Expand Down Expand Up @@ -113,7 +115,7 @@ pub fn flatten_record(records: &[Record]) -> Result<MergedRecord, String> {
}
};
}
// `merge_shards`/`merge_supported` describe the merge setup, which
// `merge_shards`/`merge_split`/`merge_supported` describe the merge setup, which
// every merge square of one invocation stamps — equal values agree,
// different ones mean two setups were folded together.
macro_rules! keep_same {
Expand Down Expand Up @@ -183,6 +185,12 @@ pub fn flatten_record(records: &[Record]) -> Result<MergedRecord, String> {
"merge_folds_per_sec"
);
keep_same!(out.merge.merge_shards, *merge_shards, "merge_shards");
// A record from before `merge_split` existed split contiguously.
keep_same!(
out.merge.merge_split,
merge_split.or(Some(MergeSplit::Contiguous)),
"merge_split"
);
keep_same!(
out.merge.merge_supported,
*merge_supported,
Expand Down Expand Up @@ -424,6 +432,30 @@ mod tests {
assert!(err.contains("merge_shards"), "{err}");
}

/// Two splits are two setups; a record without the field split
/// contiguously, so it agrees with a contiguous one.
#[test]
fn merge_split_on_two_squares_must_agree() {
let merge = |metric, split| {
record(
"merge",
metric,
BenchSection {
merge_split: split,
..Default::default()
},
)
};
let out = flatten_record(&[merge("throughput", None)]).expect("one setup");
assert_eq!(out.merge.merge_split, Some(MergeSplit::Contiguous));
let err = flatten_record(&[
merge("throughput", Some(MergeSplit::Interleaved)),
merge("accuracy", None),
])
.expect_err("two splits in one row");
assert!(err.contains("merge_split"), "{err}");
}

/// `throughput_items_per_sec` is owned by exactly one metric-pass per
/// operation — nothing legitimately produces it twice for `insert`. A
/// second value here is a genuine duplicate, refused by field name
Expand Down
2 changes: 2 additions & 0 deletions aqpbm-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ fn run_sketchbench(args: SketchbenchArgs) -> Result<()> {
width,
workers: args.workers.max(1),
merge_shards: args.merge_shards,
merge_split: args.merge_split,
group_columns,
per_group_out: args.per_group_out.as_ref().map(std::path::PathBuf::from),
comparator: args.comparator.clone(),
Expand Down Expand Up @@ -458,6 +459,7 @@ fn run_sketchbench(args: SketchbenchArgs) -> Result<()> {
// and a record states what ran rather than what was asked for.
if operation == Operation::Merge {
report.bench.merge_shards = Some(args.merge_shards.max(MIN_MERGE_SHARDS));
report.bench.merge_split = Some(args.merge_split);
}
reports.push(report);
}
Expand Down
1 change: 1 addition & 0 deletions aqpbm-cli/src/repeat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ mod tests {
accuracy: Some(serde_json::json!({"are_all": 0.01, "accuracy_runs": 5})),
merge_folds_per_sec: Some(stats(mean * 0.5)),
merge_shards: Some(4),
merge_split: None,
merge_supported: Some(true),
});
rec
Expand Down
4 changes: 2 additions & 2 deletions aqpbm-cli/src/rows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use std::rc::Rc;

use sketch_bench::request::{Dtype, Requirement};
use sketch_bench::wrappers::{
BuildError, Folds, InsertBody, InsertStepBody, ParallelInsertBody, PrepareBody, QueryBody,
QueryPass, StepPass,
interleave, BuildError, Folds, InsertBody, InsertStepBody, MergeSplit, ParallelInsertBody,
PrepareBody, QueryBody, QueryPass, StepPass,
};

/// A row that cannot be built at the requested config says so in its own words;
Expand Down
16 changes: 13 additions & 3 deletions aqpbm-cli/src/rows/statistic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ pub(super) fn scored_row<G, I>(
prepare: Option<PrepareBody<I>>,
) -> Result<Measurements, RunError>
where
I: Clone,
G: GroundTruth + 'static,
G::Truth: 'static,
G::Probe: 'static,
Expand All @@ -411,6 +412,15 @@ where
None => score,
};
let items = materialise(description, table)?;
// What the folds cut into shards: the stream itself, or reordered so the
// same cut deals it round-robin. Copied only when a merge will use it.
let merging = want
.iter()
.any(|&(operation, _)| operation == Operation::Merge);
let merged = match req.merge_split {
MergeSplit::Interleaved if merging => Rc::new(interleave(&items, shards(req))),
_ => items.clone(),
};
let mut bodies = Vec::with_capacity(want.len());
for &(operation, metric) in want {
let n = passes(req, metric);
Expand All @@ -432,7 +442,7 @@ where
(Operation::Merge, Metric::Accuracy) => answered(
merge.expect(SUPPORTED).2(
&req.params,
items.clone(),
merged.clone(),
probes.clone(),
shards(req),
n,
Expand All @@ -442,11 +452,11 @@ where
metric,
),
(Operation::Merge, Metric::Latency) => stepped(
merge.expect(SUPPORTED).1(&req.params, items.clone(), shards(req), n)
merge.expect(SUPPORTED).1(&req.params, merged.clone(), shards(req), n)
.map_err(cannot_build)?,
),
(Operation::Merge, _) => timed(
merge.expect(SUPPORTED).0(&req.params, items.clone(), shards(req), n)
merge.expect(SUPPORTED).0(&req.params, merged.clone(), shards(req), n)
.map_err(cannot_build)?,
(shards(req) - 1) as u64,
),
Expand Down
30 changes: 29 additions & 1 deletion aqpbm-core/schema/merged_record.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
"minimum": 0
},
"merge_accuracy": {
"description": "The same comparator as `query_accuracy`, against the same whole-stream\ntruth, scoring the sketch left by folding `merge_shards` contiguous\nshards. A linear sketch should match `query_accuracy` exactly."
"description": "The same comparator as `query_accuracy`, against the same whole-stream\ntruth, scoring the sketch left by folding `merge_shards` shards split\nas `merge_split` says. A linear sketch should match `query_accuracy`\nexactly under either split."
},
"merge_cpu_time_ms": {
"anyOf": [
Expand Down Expand Up @@ -147,6 +147,18 @@
"format": "uint",
"minimum": 0
},
"merge_split": {
"description": "How the stream was split into the `merge_shards` shards.",
"anyOf": [
{
"$ref": "#/$defs/MergeSplit"
},
{
"type": "null"
}
],
"default": null
},
"merge_supported": {
"type": [
"boolean",
Expand Down Expand Up @@ -322,6 +334,7 @@
"merge_heap_allocated_kb",
"merge_rss_peak_kb",
"merge_shards",
"merge_split",
"merge_supported",
"merge_timestamp",
"merge_wall_time_ms",
Expand Down Expand Up @@ -712,6 +725,21 @@
"count"
]
},
"MergeSplit": {
"description": "How a merge run split the stream into its shards.",
"oneOf": [
{
"description": "Each shard a consecutive stretch of the stream.",
"type": "string",
"const": "contiguous"
},
{
"description": "Round-robin by record over the contiguous split's shard sizes, so each\nshard is a sample of the whole stream.",
"type": "string",
"const": "interleaved"
}
]
},
"Mode": {
"type": "string",
"enum": [
Expand Down
2 changes: 1 addition & 1 deletion aqpbm-core/src/benchmark_result/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub use bench_report::BenchReport;
pub use fold::MemoryMaxima;
pub use schema::{
BenchSection, CpuTime, ExternalWorkload, InsertMetrics, Language, LatencySummary, MergeMetrics,
MergedRecord, Mode, PrepareMetrics, QueryMetrics, Record, RunStats, Source,
MergeSplit, MergedRecord, Mode, PrepareMetrics, QueryMetrics, Record, RunStats, Source,
WorkloadDescription, SCHEMA_VERSION,
};
pub use welford::Welford;
37 changes: 35 additions & 2 deletions aqpbm-core/src/benchmark_result/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,30 @@ pub enum Source {
CppBench,
}

/// How a merge run split the stream into its shards.
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum MergeSplit {
/// Each shard a consecutive stretch of the stream.
#[default]
Contiguous,
/// Round-robin by record over the contiguous split's shard sizes, so each
/// shard is a sample of the whole stream.
Interleaved,
}

impl std::str::FromStr for MergeSplit {
type Err = String;
fn from_str(s: &str) -> Result<Self, String> {
match s {
"contiguous" => Ok(Self::Contiguous),
"interleaved" => Ok(Self::Interleaved),
other => Err(format!("unknown merge split '{other}'")),
}
}
}

/// MACRO (benchmark) section of a record. Every sub-field is
/// `Option`al so N/A metrics don't pollute the JSON with zero
/// placeholders.
Expand Down Expand Up @@ -179,6 +203,11 @@ pub struct BenchSection {
/// if the implementation turned out not to support merging.
#[serde(skip_serializing_if = "Option::is_none")]
pub merge_shards: Option<usize>,
/// How the stream was split into those shards. Present whenever merge was
/// measured; absent on records written before the field existed, which
/// all split contiguously.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub merge_split: Option<MergeSplit>,
/// Present, and `true`, whenever a merge was measured. Never `false`: a row
/// that provides no merge is refused where the closures are built, before anything
/// is timed, so the gap shows up as an error naming the row rather than as a
Expand Down Expand Up @@ -323,10 +352,14 @@ pub struct MergeMetrics {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub merge_folds_per_sec: Option<RunStats>,
pub merge_shards: Option<usize>,
/// How the stream was split into the `merge_shards` shards.
#[serde(default)]
pub merge_split: Option<MergeSplit>,
pub merge_supported: Option<bool>,
/// The same comparator as `query_accuracy`, against the same whole-stream
/// truth, scoring the sketch left by folding `merge_shards` contiguous
/// shards. A linear sketch should match `query_accuracy` exactly.
/// truth, scoring the sketch left by folding `merge_shards` shards split
/// as `merge_split` says. A linear sketch should match `query_accuracy`
/// exactly under either split.
#[serde(rename = "merge_accuracy")]
pub accuracy: Option<serde_json::Value>,
#[serde(rename = "merge_cpu_time_ms")]
Expand Down
4 changes: 2 additions & 2 deletions aqpbm-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ pub use atomic_costs::{
};
pub use benchmark_result::{
BenchReport, BenchSection, CpuTime, ExternalWorkload, InsertMetrics, LatencySummary,
MergeMetrics, MergedRecord, Mode, PrepareMetrics, QueryMetrics, Record, RunStats, Source,
WorkloadDescription, SCHEMA_VERSION,
MergeMetrics, MergeSplit, MergedRecord, Mode, PrepareMetrics, QueryMetrics, Record, RunStats,
Source, WorkloadDescription, SCHEMA_VERSION,
};
pub use erp::{
erp_artifact, erp_record, ErpArtifact, ErpRecord, ErpResourceProfile, ERP_SCHEMA_VERSION,
Expand Down
3 changes: 2 additions & 1 deletion docs/saturation_study.md
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,8 @@ Crossover at theta = 1, K = 1e5 (frequency, top-k, HLL) and Pareto alpha 1.5
- **Accuracy after merging** is now measured (`--operations merge --metrics
accuracy --merge-shards m`, or `--merge-shards-list 1,4,16,64` here, into
`saturation_merge_curve.csv`): the N-item stream is split into m contiguous
shards, one sketch per shard is folded into one, and it is scored with the
shards (approxbench `--merge-split interleaved` deals it round-robin), one
sketch per shard is folded into one, and it is scored with the
query's comparator against the whole-stream truth. A bounded run (first
config per sketch, N up to 1e7, 3 seeds, theta 0.5/1.0/1.5, K 1e3/1e5/1e7,
alpha 1.1/2) found:
Expand Down
2 changes: 2 additions & 0 deletions sketch-bench/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ pub struct Requirement {
pub workers: usize,
/// How many shards a merge measurement folds
pub merge_shards: usize,
/// How a merge measurement splits the stream into those shards
pub merge_split: crate::wrappers::MergeSplit,
/// The label columns a grouped (`hydra-*`) row asks and scores, ascending
pub group_columns: Vec<usize>,
/// Where a grouped row writes each scored group's error, if anywhere
Expand Down
Loading
Loading