Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
296621f
test(cost): default unit costs rank exact against sketch plans as the…
zzylol Nov 15, 2026
466d497
fix(cost): charge each operation the executor's measured time per unit
zzylol Nov 15, 2026
b75a449
test(cost): name the executor commit the ranking expectations were me…
zzylol Nov 15, 2026
fb65262
test(cost): compaction latency charges each merge its family's merge …
zzylol Nov 15, 2026
213a14c
fix(cost): per-family compaction merges, one CPU-operation unit, revi…
zzylol Nov 15, 2026
b973faf
test(planner): sum by (job) (rate) at 10 Hz with unknown arrival inst…
zzylol Nov 15, 2026
ddc8b28
fix(cost): a query-time chain pays the time range over the rows it reads
zzylol Nov 15, 2026
afd1495
test(cost): no compaction for nodes holding no states; a query-time c…
zzylol Nov 15, 2026
a9c9cc4
fix(cost): compaction merges only nodes holding states; review round …
zzylol Nov 15, 2026
6f36a63
test(cost): rebase onto main: the new ProducerOutputs in the unit-cos…
zzylol Nov 16, 2026
c1b6a0e
test: rebase onto main: main's Stage 3 tests under the measured unit …
zzylol Nov 16, 2026
5caac06
refactor(cost): rebase onto main: operations_per_unit lists every var…
zzylol Nov 16, 2026
ec15a37
test: rebase onto main: main's DDSketch byte tests call sketch_state_…
zzylol Nov 16, 2026
91913fe
test(planner): rebase onto main: MetricsQL answers are checked on dat…
zzylol Nov 16, 2026
91f367c
test(planner): force the shared query-time rate chain by data at rest…
zzylol Nov 16, 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
6 changes: 6 additions & 0 deletions crates/cost/src/measured.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
//! covering every operator kind the plans use makes the choice the
//! measured one (plan selection's module doc, "Measured operation costs").
//!
//! Without a table, the formulas are not unit-free guesses: they carry the
//! reference executor's measured time per unit of work
//! (`node::operations_per_unit`), the built-in fallback. A table measured
//! on the deployment's own machine (by a calibration run of its executor)
//! overrides them node by node.
//!
//! A measured time enters [`ResourceUsage`] as CPU operations: `t` ns is
//! `t · 10⁻⁶ / ms_per_cpu_op` operations of [`ResourceSpeed`], so latency
//! (operations × `ms_per_cpu_op`) is the measured time, and every cost model
Expand Down
9 changes: 7 additions & 2 deletions crates/cost/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ pub struct ResourceUnitCost {

impl ResourceUnitCost {
/// The prices plan selection uses until a deployment is calibrated:
/// 1 ns of CPU per operation, 0.1 ns per scanned byte, 1 GB retained for a
/// 1 ns of CPU per operation (one operation is one ns of the reference
/// executor's work, [`ResourceSpeed::ms_per_cpu_op`]), 0.1 ns per scanned byte, 1 GB retained for a
/// second costs 1/8 vCPU (125 CPU-ms), held or provisioned alike; one
/// provisioned core-second is 1,000 CPU-ms. Disk is not priced (0).
pub fn illustrative() -> Self {
Expand Down Expand Up @@ -117,7 +118,11 @@ impl ResourceUnitCost {
#[derive(Debug, Clone, Copy, PartialEq, serde::Serialize, serde::Deserialize)]
#[serde(deny_unknown_fields)]
pub struct ResourceSpeed {
/// Milliseconds one CPU operation takes on one core.
/// Milliseconds one CPU operation takes on one core. One CPU operation
/// is one nanosecond of the reference executor's work
/// (`node::operations_per_unit`), so the default is 1e-6; for another
/// machine set this to 1e-6 × its time ÷ the reference time (a core
/// half as fast: 2e-6).
pub ms_per_cpu_op: f64,
/// Milliseconds scanning one byte takes on one core.
pub ms_per_scanned_byte: f64,
Expand Down
37 changes: 18 additions & 19 deletions crates/cost/src/node/analytical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//! separate. Plan selection (Stage 3) turns them into one objective with
//! [`crate::ResourceUnitCost`].

use crate::node::operations_per_unit::TIME_RANGE_OPERATIONS_PER_ROW;
use crate::resources::ModeledCpu;
use asap_types::summary_type::{SketchAlgorithm, SketchParams};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -96,7 +97,11 @@ pub(crate) enum PhysicalOperator {
},
HashAggregate {
grouping_key_count: u64,
accumulator_count: u64,
/// CPU operations one input row costs, its grouping keys and
/// measures together
/// (`operations_per_unit::hash_aggregate_operations_per_row`):
/// 27 for a per-series `max_over_time` (one key, one measure).
operations_per_row: u64,
},
InMemoryComparisonSort {
ordering_key_count: u64,
Expand Down Expand Up @@ -443,7 +448,7 @@ pub(crate) fn estimate_operator(
),
(PhysicalOperator::TimeShift, _) => ResourceEstimate::new(0.0, 0, 0),
(PhysicalOperator::TimeRange, _) => ResourceEstimate::new(
output.rows as f64,
output.rows as f64 * TIME_RANGE_OPERATIONS_PER_ROW,
per_row_width(output.rows, output.bytes)?,
0,
),
Expand All @@ -454,8 +459,7 @@ pub(crate) fn estimate_operator(
),
(
PhysicalOperator::HashAggregate {
grouping_key_count,
accumulator_count,
operations_per_row, ..
},
OperatorStatistics::HashAggregate {
group_count,
Expand All @@ -464,12 +468,7 @@ pub(crate) fn estimate_operator(
..
},
) => ResourceEstimate::new(
checked_cpu_product(
left.rows,
grouping_key_count
.checked_add(accumulator_count)
.ok_or(AnalyticalCostError::Overflow)?,
)?,
checked_cpu_product(left.rows, operations_per_row)?,
checked_bytes(&[
*group_count,
key_bytes
Expand Down Expand Up @@ -842,7 +841,7 @@ pub(crate) fn validate_operator_semantics(
(
PhysicalOperator::HashAggregate {
grouping_key_count,
accumulator_count,
operations_per_row,
},
OperatorStatistics::HashAggregate {
group_count,
Expand All @@ -856,7 +855,7 @@ pub(crate) fn validate_operator_semantics(
"PromQL cross-series aggregation needs an explicit physical operator",
);
}
if accumulator_count == 0 || *accumulator_bytes_per_group == 0 {
if operations_per_row == 0 || *accumulator_bytes_per_group == 0 {
return inconsistent("HashAggregate accumulator work and width must be positive");
}
if grouping_key_count == 0 {
Expand Down Expand Up @@ -1578,8 +1577,8 @@ mod tests {
}

/// A time shift only moves when its input is evaluated: it costs
/// nothing. A time range is priced by the rows it keeps, and keeps no
/// more than it reads.
/// nothing. A time range is priced by the rows it keeps (12 measured
/// operations each), and keeps no more than it reads.
#[test]
fn time_shift_is_free_and_time_range_is_priced_by_the_rows_it_keeps() {
let shift = estimate_operator(
Expand All @@ -1598,7 +1597,7 @@ mod tests {
},
)
.unwrap();
assert_eq!(range.cpu_ops(), 200.0);
assert_eq!(range.cpu_ops(), 200.0 * TIME_RANGE_OPERATIONS_PER_ROW);
assert!(estimate_operator(
PhysicalOperator::TimeRange,
OperatorStatistics::PassThrough {
Expand Down Expand Up @@ -1630,7 +1629,7 @@ mod tests {
fn aggregate_operator() -> PhysicalOperator {
PhysicalOperator::HashAggregate {
grouping_key_count: 1,
accumulator_count: 1,
operations_per_row: 1,
}
}

Expand Down Expand Up @@ -1792,7 +1791,7 @@ mod tests {
estimate_operator(
PhysicalOperator::HashAggregate {
grouping_key_count: 0,
accumulator_count: 1,
operations_per_row: 1,
},
statistics,
),
Expand Down Expand Up @@ -2126,7 +2125,7 @@ mod tests {
let ungrouped = estimate_operator(
PhysicalOperator::HashAggregate {
grouping_key_count: 0,
accumulator_count: 1,
operations_per_row: 1,
},
OperatorStatistics::HashAggregate {
edges: unary_edges(empty, EdgeStatistics { rows: 1, bytes: 8 }),
Expand All @@ -2142,7 +2141,7 @@ mod tests {
let grouped = estimate_operator(
PhysicalOperator::HashAggregate {
grouping_key_count: 1,
accumulator_count: 1,
operations_per_row: 1,
},
OperatorStatistics::HashAggregate {
edges: unary_edges(empty, empty),
Expand Down
4 changes: 3 additions & 1 deletion crates/cost/src/node/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
//! One node of a physical plan DAG: its resource usage and cost
//! (`usage`), from the analytical per-operator resource model
//! ([`analytical`], `operator_statistics`) and the bytes a state holds
//! ([`analytical`], `operator_statistics`), the measured CPU operations per
//! unit of work (`operations_per_unit`) and the bytes a state holds
//! ([`state_bytes`]).

pub mod analytical;
pub(crate) mod operations_per_unit;
pub(crate) mod operator_statistics;
pub mod state_bytes;
pub(crate) mod usage;
Loading
Loading