Skip to content

Add sliding-window RQE deployment optimizer - #129

Merged
milindsrivastava1997 merged 10 commits into
mainfrom
dev-milind-turboprom
Oct 4, 2026
Merged

milindsrivastava1997 merged 10 commits into
mainfrom
dev-milind-turboprom

Conversation

@milindsrivastava1997

@milindsrivastava1997 milindsrivastava1997 commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This PR adds a sketch-deployment optimizer for a workload of repeating query
expressions (RQEs). Given measured sketch-bench data and a workload, it
generates legal sliding-window deployments and selects a low-CPU plan without
eagerly enumerating every RQE-to-deployment mapping.

The main addition is a HiGHS-backed mixed-integer linear program (MILP). It
supports overlapping deployments (x > y), deployment sharing across
compatible RQEs, and optional query-latency limits.

Examples

First export the measured cost table:

scripts/export_rqe_optimizer_costs.sh

Inspect candidates without enumerating mappings:

cargo run -p rqe-optimizer --example small_problem -- \
  --candidates-only --print-candidates 5

Print a few feasible mappings, then exit:

cargo run -p rqe-optimizer --example small_problem -- \
  --sample-mappings 3

Solve for minimum steady-state CPU:

cargo run -p rqe-optimizer --example small_problem -- --milp

Solve with a 3 ms limit on the 1-day p99 query:

cargo run -p rqe-optimizer --example small_problem -- --milp \
  --latency-limit latency_p99_1d=0.003

Safety

Do not run cargo run -p rqe-optimizer --example small_problem with no
mode flag on a large workload.
Eager mode retains every feasible mapping and
can exhaust memory. --streaming avoids retaining all mappings, but can still
run for a long time as its Pareto frontier grows. Use --candidates-only,
--sample-mappings N, or --milp for bounded inspection and optimization.

Candidate model

A deployment is:

(capability, sketch configuration, labels, window x, slide y)

x > y is supported. Each arriving item updates x / y active overlapping
instances.

For an RQE with lookback S and interval T, a deployment is eligible when
its capability, labels, and measured accuracy match, and:

x % y == 0
S % x == 0
T % y == 0

A query merges exactly S / x non-overlapping instances. Candidate dominance
pruning removes a candidate only when another candidate can serve every same
RQE with no worse query memory, ingest CPU, or per-RQE latency.

MILP

Inputs

  • RQEs: capability, label set, lookback S, interval T, accuracy metric,
    and accuracy tolerance.
  • Label-set facts: physical group count and aggregate arrival rate in
    items/sec.
  • Measured sketch rows: memory per instance; CPU per inserted item, merge,
    and query; plus measured accuracy metrics.
  • Optional limits: peak query-memory budget and per-RQE query-latency
    limits.

Decision variables and constraints

For each eligible RQE/deployment pair, z[i,d] is binary and means RQE i
uses deployment d. u[d] is binary and means deployment d is active.
M is continuous peak query memory.

The model requires every RQE to choose one eligible deployment, makes every
selected deployment active, prevents unused active deployments, and ensures
M covers every selected query working set. Optional memory and latency
limits are hard constraints.

Objective

The current solve minimizes steady-state CPU:

TCO = ingest CPU + query CPU + merge CPU

Ingest is charged once per active deployment:

arrival_rate(labels) × (x / y) × insert_cpu_per_item

Query and merge CPU are charged per RQE at that RQE's interval.

Outputs

A solve returns one deployment for each RQE, including sketch configuration,
x, and y, plus peak query working memory; ingest, merge, query, and total
steady-state CPU; and estimated latency for every RQE.

Current modeling boundaries

  • Accuracy eligibility uses measured accuracy for one sketch instance. It does
    not yet validate final accuracy after merging S / x instances.
  • Query memory is one query's working set: groups × bytes per instance. It
    excludes retained storage, merge buffers, and concurrent queries.
  • Label cardinality and arrival rate are static workload inputs.
  • Query-result reuse between compatible RQEs is not modeled.
  • Rollups, migration, re-planning, and RQE churn are not modeled.

Next work

Correctness and measurement

  • Measure or validate accuracy after merging multiple instances, likely with
    an accuracy profile keyed by configuration, logical data volume, and merge
    depth.

Optimization

  • Generate a Pareto frontier through repeated bounded MILP solves or normalized
    weighted objectives.
  • Add a hard cap to legacy streaming-enumerator experiments.

Deferred scope

  • Query-result sharing, after RQE semantics and evaluation phase are explicit
    enough to prove reuse safe.
  • Retained-storage, merge-buffer, and concurrent-query memory.
  • A policy for choosing one result from a Pareto frontier.
  • Additional capabilities beyond frequency, quantile, cardinality, and top-k.

Validation

  • cargo test -p rqe-optimizer (12 tests)
  • cargo clippy -p rqe-optimizer --all-targets -- -D warnings
  • A regression test confirms the MILP matches exhaustive minimum-TCO search on
    a small workload with shared deployment activation costs.
  • Candidate and mapping sample modes are exercised without full mapping
    enumeration.

@milindsrivastava1997
milindsrivastava1997 marked this pull request as ready for review October 4, 2026 14:22
@milindsrivastava1997
milindsrivastava1997 merged commit 6c487b2 into main Oct 4, 2026
4 checks passed
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