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
b30eaf5
fix(cost): charge DDSketch states their expected bytes, KLL merges by…
zzylol Nov 16, 2026
d0190fe
test(cost): the declared range caps a DDSketch's span; Max merges and…
zzylol Nov 16, 2026
6d5a127
fix(cost): cap a DDSketch's span by the declared range; Max merges, e…
zzylol Nov 16, 2026
28345ce
test(cost): an ingestion-time chain assigns each row its window; a KL…
zzylol Nov 16, 2026
fede553
fix(cost): an ingestion-time chain pays a time range per row; a KLL r…
zzylol Nov 16, 2026
ccff3ba
docs(cost): a declared magnitude range caps a DDSketch's span; the ch…
zzylol Nov 16, 2026
f7e5d2d
test(cost): a grouping costs more per row at a lower sample rate; a K…
zzylol Nov 16, 2026
b9c2e0b
fix(cost): a grouping pays once per group and raw batch, shared by ha…
zzylol Nov 16, 2026
e8fd332
docs(cost): the per group and raw batch visit, the raw batch width in…
zzylol Nov 16, 2026
fc4d670
test(cost): batches counted from the time the input spans; a one-stat…
zzylol Nov 16, 2026
b62c370
fix(cost): raw batches from the time the input spans; one-state merge…
zzylol Nov 16, 2026
6ca12f8
docs(cost): raw batches from the time the input spans, the data store…
zzylol Nov 16, 2026
dcaabce
test(cost): a rollup merges its states when its group estimate ties i…
zzylol Nov 16, 2026
b138585
fix(cost): a rollup merges its states when its group estimate ties it…
zzylol Nov 16, 2026
e089d2f
docs(cost): a rollup merges its states when its estimate ties its inp…
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 @@ -106,6 +106,12 @@ pub struct OperatorCost {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub measure: Option<String>,
/// CPU nanoseconds per unit the operator processes ([`OperatorKind`]).
/// It includes what the formulas charge apart, at the measured shape:
/// the output rows a merge, an aggregate or an estimate builds per
/// group and the label columns a grouping carries per row. Example: a
/// `SummaryMerge` entry measured over 360 states per group holds its
/// per-group output row as a 360th of it per state; at 5 states per
/// group that row is under-charged.
pub ns_per_unit: f64,
/// CPU nanoseconds per computation of the node, whatever its units:
/// per evaluation at query time, per second of arriving rows at
Expand Down
39 changes: 35 additions & 4 deletions crates/cost/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ impl ResourceUnitCost {
}
}

/// How fast one core does work; the latency check reads it.
/// How fast one core does work, and the batches of raw rows its work is
/// split into; the latency check reads it.
#[derive(Debug, Clone, Copy, PartialEq, serde::Serialize, serde::Deserialize)]
#[serde(deny_unknown_fields)]
pub struct ResourceSpeed {
Expand All @@ -126,16 +127,39 @@ pub struct ResourceSpeed {
pub ms_per_cpu_op: f64,
/// Milliseconds scanning one byte takes on one core.
pub ms_per_scanned_byte: f64,
/// The time one batch of raw rows covers in the deployment's data
/// store, which returns raw rows to a query in those batches, each
/// series' rows of a batch together. The executor has no batch width of
/// its own: it groups the batches the store returns and looks up a
/// series' group once per batch, so a grouping visits each group's
/// state once per batch its rows are in. A 5 min window of a series
/// sampled at 1 Hz in 10 s batches costs 30 visits per series, whether
/// it holds 300 rows or (at 10 Hz) 3,000. Default 10,000 (10 s), an
/// assumed value: the batch width of the store the reference
/// measurements read from, not one the deployment declared; omitted
/// from JSON, it takes that default. Ingestion-time work is charged
/// one second's share of a batch per execution, which follows the
/// arriving rows, not the store's batches.
#[serde(default = "default_raw_batch_width_ms")]
pub raw_batch_width_ms: u64,
}

/// The assumed [`ResourceSpeed::raw_batch_width_ms`]: 10 s.
const DEFAULT_RAW_BATCH_WIDTH_MS: u64 = 10_000;

fn default_raw_batch_width_ms() -> u64 {
DEFAULT_RAW_BATCH_WIDTH_MS
}

impl ResourceSpeed {
/// 1 ns per operation and 0.1 ns per scanned byte, the times
/// [`ResourceUnitCost::illustrative`] prices: one cost unit is one
/// millisecond of one core.
/// millisecond of one core. Raw rows in 10 s batches (assumed).
pub(crate) fn illustrative() -> Self {
Self {
ms_per_cpu_op: 1e-6,
ms_per_scanned_byte: 1e-7,
raw_batch_width_ms: DEFAULT_RAW_BATCH_WIDTH_MS,
}
}
}
Expand Down Expand Up @@ -239,8 +263,8 @@ impl Default for CostInputs {
}

impl CostInputs {
/// Bad input: a negative or non-finite speed, a horizon that is not
/// positive, a bad measured table ([`MeasuredOperationCosts`]: a
/// Bad input: a negative or non-finite speed, a raw batch width of 0, a
/// horizon that is not positive, a bad measured table ([`MeasuredOperationCosts`]: a
/// negative or non-finite time or size, an entry naming two families,
/// a duplicate entry, or `ms_per_cpu_op` 0), or a price the chosen cost model reads that is negative or
/// not finite, or every such price 0 (cost model 3 reads none).
Expand All @@ -259,6 +283,12 @@ impl CostInputs {
return Err(AnalyticalCostError::InvalidCalibration(name, value));
}
}
if self.resource_speed.raw_batch_width_ms == 0 {
return Err(AnalyticalCostError::InvalidCalibration(
"raw_batch_width_ms",
0.0,
));
}
let horizon = self.non_repeating_query_horizon_seconds;
if !horizon.is_finite() || horizon <= 0.0 {
return Err(AnalyticalCostError::InvalidCalibration(
Expand Down Expand Up @@ -381,6 +411,7 @@ mod tests {
let slower = ResourceUnitCost::aws_fargate_us_east_1(ResourceSpeed {
ms_per_cpu_op: 2e-6,
ms_per_scanned_byte: 2e-7,
..ResourceSpeed::illustrative()
});
close(slower.cost_per_cpu_op, 2.2488e-14);
close(slower.cost_per_scanned_byte, 2.2488e-15);
Expand Down
10 changes: 7 additions & 3 deletions crates/cost/src/node/analytical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
//! 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::node::operations_per_unit::{
OUTPUT_ROW_OPERATIONS_PER_GROUP, TIME_RANGE_OPERATIONS_PER_ROW,
};
use crate::resources::ModeledCpu;
use asap_types::summary_type::{SketchAlgorithm, SketchParams};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -468,7 +470,8 @@ pub(crate) fn estimate_operator(
..
},
) => ResourceEstimate::new(
checked_cpu_product(left.rows, operations_per_row)?,
checked_cpu_product(left.rows, operations_per_row)?
+ *group_count as f64 * OUTPUT_ROW_OPERATIONS_PER_GROUP,
checked_bytes(&[
*group_count,
key_bytes
Expand Down Expand Up @@ -2135,7 +2138,8 @@ mod tests {
},
)
.unwrap();
assert_eq!(ungrouped.cpu_ops(), 0.0);
// No row to fold; its one output row is still built.
assert_eq!(ungrouped.cpu_ops(), OUTPUT_ROW_OPERATIONS_PER_GROUP);
assert_eq!(ungrouped.peak_memory_bytes(), 24);

let grouped = estimate_operator(
Expand Down
Loading
Loading