Skip to content

rqe-optimizer: one study for sketch cost and accuracy #174

Closed

Description

@milindsrivastava1997

Problem

rqe-optimizer reads its inputs from two separate runs of the same binary (approxbench sketchbench):

  • scripts/export_rqe_optimizer_costs.sh builds AtomicCostTable: insert/merge/query CPU and memory per (sketch, config), plus one accuracy point (N=1e6, Zipf 1.1) and a merge-accuracy sweep (4–1024 shards).
  • scripts/study_saturation.py builds the error-vs-N curves (plus merge curves via --merge-shards-list) over a grid of data shapes. Its --phase cost also measures insert/merge/query CPU and memory, but its docstring calls these "indicative" and defers to the export.

Since #171 the optimizer reads accuracy for lossy sketches only from the curves. This leaves:

  • Dead measurement: the export's accuracy pass and merge-accuracy sweep (rqe_merge_accuracy_grid.jsonl, atomic-costs --merge-accuracy) no longer feed the optimizer.
  • Duplicated measurement: both scripts measure cost, with different settings (export: 5 runs / 3 warmup at N=1e6; study: 3 runs / 1 warmup, BENCH_WARMUP_SECS=0, at the final N).
  • Drift-check code: SaturationCurves::check_cost_table exists only to confirm that the two runs agree at the table's measured_at.
  • Leftover consumer paths: AtomicCostEntry.query_accuracy / merge_accuracy, accuracy_at, table_accuracy(_at) are reached only through exact accumulators (whose error is trivially 0) and tests.
  • Grid kept in sync by hand: the export's configs are chosen to be "points of the saturation grid" (Candidate generation ignores saturation: deployments whose instances never reach N_sat are planned #156). A config missing from either side is silently ineligible.

Proposed solution

Make the saturation study the single source of optimizer inputs.

Script (study_saturation.py)

  • The cost phase measures once per (sketch, config) at one canonical data shape, not once per shape, using the export's run and warmup counts. It stays serial, so it can be timed on a quiet machine (--phase cost already supports this).
  • Add cost-only rows for the exact accumulators (sum, min, max, increase, delta set).
  • Emit cost in a form the optimizer loads directly (or reduce it with atomic-costs, without --merge-accuracy).
  • Delete scripts/export_rqe_optimizer_costs.sh. Leave scripts/export_atomic_costs.sh (ASAPQuery's pinned grid) untouched.
  • UnivMon and HydraKLL have no curves, so they are ineligible today (Candidate generation ignores saturation: deployments whose instances never reach N_sat are planned #156, rqe-optimizer: drop hydra-kll from Quantile candidates #170). Leave them out until they get curves.

Consumer (rqe-optimizer)

  • --saturation-dir supplies both cost (keyed by config) and accuracy (keyed by config and shape). Drop the separate cost-table input in small_problem.
  • Exact accumulators return a constant 0 error instead of reading the table.
  • Remove query_accuracy / merge_accuracy from AtomicCostEntry, accuracy_at, table_accuracy(_at), and check_cost_table.

Open question

This assumes per-config cost is roughly independent of data shape. That holds for CMS, HLL, KLL and DDSketch. Heap top-k insert cost does depend on skew, but the current table ignores that too, so nothing is lost. If it turns out to matter, key cost by shape; the study already loops over shapes.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions