Skip to content

Countsketch benchmark - #28

Closed
GnaneshGnani wants to merge 4 commits into
mainfrom
countsketch_benchmark
Closed

GnaneshGnani wants to merge 4 commits into
mainfrom
countsketch_benchmark

Conversation

@GnaneshGnani

Copy link
Copy Markdown
Contributor

Adds benchmarking infrastructure for the CountSketch processor

Features:

Automated benchmark script with Zipf-distributed metric loads
Microsecond-precision intervals for >99.8% throughput accuracy
Comprehensive metrics tracking (CPU, memory, throughput, latency)

Results (10k-50k MPS):

Throughput: >99.9% accuracy

CPU: Linear scaling, max 54.24% at 50k MPS

Memory: Stable 36-39 MB

Zero data loss, <3ms latency

Results: otel_collector_benchmark/benchmark_results/countsketchcol/

@GnaneshGnani
GnaneshGnani deleted the countsketch_benchmark branch January 13, 2026 21:50
zzylol added a commit that referenced this pull request May 6, 2026
…eys CSE legality (#277)

Per design.md §6 `core::cost` (line ~997) and Schema flow (line ~425),
land the workload-level cost-model entry point + the load-bearing
consumer of `Schema::unique_keys`. Phase A/B/D shipped the typed types,
the L3 IR DAG with `Schema::unique_keys`, and the language wrap; Phase F
is what makes `unique_keys` "load-bearing" and what credits shared
sub-DAGs in the bundled cost.

What lands:

- `planner::cost_model::workload_cost(plan: &WorkloadCostPlan<'_>) ->
  Result<WorkloadCost, QueryExprError>` — walks the L3 IR DAG (Phase B's
  `intent_algebra::QueryExpr`) post-order, memoises by `LetBinding`
  name, credits each shared producer once across consumers. Returns
  `WorkloadCost { total_dollars, per_root_breakdown, reused_savings }`.
  `reused_savings` exposes the gap between the bundled total and the
  naive sum-over-roots, for EXPLAIN / observability per design.md §6
  line ~1023.
- `planner::cost_model::WorkloadCostPlan { bindings, roots }` — the
  cost-model's view of `types_v2::WorkloadPlan` carrying real
  `&QueryExpr` references rather than the `QueryExprPlaceholder` JSON-
  wire string. Collapses into `types_v2::WorkloadPlan` when the
  placeholder is swapped for live `QueryExpr` downstream.
- `intent_algebra::schema::cse_reuse_is_legal(producer_schema,
  consumer_count) -> Result<(), CseError>` — the gatekeeper. Two
  `QueryExpr::Ref` consumers may share a producer only when the
  producer's output schema has at least one `unique_keys` set and the
  consumer count is ≥ 2. This is the proof point that `Schema::unique_keys`
  is load-bearing — without it the deduper conservatively refuses to
  share and reuse "drops on the floor" (design.md §6 line ~1356).
- `intent_algebra::cse::dedupe_subtrees(roots) -> CseWorkloadPlan` —
  basic implementation of the workload-level CSE pass. Detects shared
  `Aggregate` children across ≥2 roots, gates on `cse_reuse_is_legal`,
  hoists into a `LetBinding`. The full alpha-equivalence + nested-CSE
  algorithm is downstream — Phase F lands the gate + the basic case so
  the cost-model side has something to credit.

Per-node cost primitives at L3 (`node_cost_scan`, `node_cost_window`,
`node_cost_aggregate`, `intent_cost`) are coarse-but-monotonic
placeholders calibrated against schema width and intent kind. What
Phase F pins is the *shape* (positive, additive, savings invariant
`bundled_total ≤ naive_sum`); calibration against real benchmarks is
downstream.

Tests added (15):

- `planner::cost_model::workload_cost_tests` (7):
  - `workload_cost_single_root_equals_query_cost` — degenerate case
  - `workload_cost_two_roots_no_sharing_equals_sum` — independent queries
  - `workload_cost_two_roots_shared_window_credits_once` — design.md
    batched-queries example: 2 quantile queries share Window+Scan;
    `reused_savings ≈ shared_cost`
  - `workload_cost_three_roots_two_share_partial` — q1+q2 share, q3
    independent; savings = 1× shared_cost
  - `workload_cost_three_roots_all_share_one_binding` — three consumers,
    savings = 2× shared_cost
  - `workload_cost_unused_binding_is_zero_savings_not_negative` —
    defensive non-negative invariant
  - `workload_cost_unresolved_ref_errors` — `Ref` to undeclared name
    surfaces as `UnresolvedRef`
- `intent_algebra::schema::tests` (4 added — total 8 with the 4
  pre-existing schema tests):
  - `cse_reuse_legal_when_unique_keys_set` — green path
  - `cse_reuse_illegal_when_unique_keys_empty` — refused without
    unique_keys
  - `cse_reuse_rejects_single_consumer` — short-circuit for count < 2
  - `cse_reuse_consumer_check_precedes_unique_key_check` — error-
    ordering invariant
- `intent_algebra::cse::tests` (4):
  - `dedupe_subtrees_empty_input`
  - `dedupe_subtrees_single_root_passthrough`
  - `dedupe_subtrees_basic` — design.md batched-queries example: two
    queries with identical `Window` sub-trees get hoisted
  - `dedupe_subtrees_no_shared_subexpr` — no fan-in detected → no
    binding emitted

design.md grows two "Implementation status" subsections — one under
`core::cost` describing what `workload_cost` ships and what's deferred
(per-plan latency split, `ReusedComponent` enumeration), and one under
the Schema flow table describing `cse_reuse_is_legal` + the basic
`dedupe_subtrees` shape.

Note on cargo test status. The controller's `cargo test` target was
already broken at origin/main (post-#275): nine `data_sink` field-init
errors in `src/config/agent.rs`, `src/config/asapquery_backend.rs`,
`src/config/precompute.rs`, and `src/main.rs` test code. This is the
pre-existing baseline blocker called out in the orchestrator spec
(separate fix in flight, #28). `cargo build --release -p controller`
and `cargo clippy --release --bin controller` both come out at the same
warning / error count as `origin/main` (132 build warnings, 162 clippy
errors — all pre-existing in unmodified files). Phase F adds zero new
warnings or clippy errors.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant