Skip to content

feat(monitor): communication-efficient distributed L2/F2 monitoring (Count-Sketch + geometric safe-zone) - #378

Merged
zzylol merged 3 commits into
mainfrom
feat/l2-f2-distributed-monitor
Jun 17, 2026
Merged

zzylol merged 3 commits into
mainfrom
feat/l2-f2-distributed-monitor

Conversation

@zzylol

@zzylol zzylol commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

The L2 counterpart to the L1 slack-countdown coordinator — real implementation, in two layers.

Layer 1 — correct distributed F2 over Count-Sketches

F2 = ‖f‖₂² does not merge linearly: F2(Σ_i f_i) = Σ_i F2(f_i) + 2 Σ_{i<j} ⟨f_i, f_j⟩. The fix is a linear sketch: a Count-Sketch row C[r][b] = Σ_{x:h_r(x)=b} s_r(x) f(x) is linear in updates, so C_merged = Σ_i C_i and Σ_b C_merged[r][b]² estimates F2(Σ_i f_i)squaring the merged sketch recovers the cross terms.

  • CountSketchF2d rows × w buckets, ±1 sign; update / linear merge / estimate_f2 (median over rows of Σ_b C[r][b]²); w=O(1/ε²), d=O(log 1/δ). Hashing = murmur3 fmix64, different seed per row + different salt for bucket vs sign.
  • DistributedF2Monitor — merges per-edge sketches, estimates global F2̂, fires at F2̂ ≥ (1−ε)τ, and does the L2 coordinated-sampling allocation p_i ∝ √(F2̂_i / rate_i) (var_budget = ε²·F2̂).

Layer 2 — geometric safe-zone (communication-efficient, breaks the circularity)

Shipping the sketch every window defeats CDM and creates a circularity: you need the global L2 to decide whether to send, but you need the sketch to get the L2. GeometricF2Monitor (Sharfman–Schuster–Keren) resolves it:

  • Each site runs a purely local test — does its drift ball B(C_ref + (k/2)ΔC_i, (k/2)‖ΔC_i‖) stay inside the safe ball B(0, √(d·τ))? — using only the last-broadcast C_ref and its own drift, never the live global.
  • A site ships its sketch only when locally unsafe → resync.
  • Convexity: global C=(1/k)Σ u_i (u_i=C_ref+k·ΔC_i) is in the convex hull, so all balls ⊆ B(0,R)‖C‖<R ⇒ F2<τ (no missed crossing). F2 is the clean case — its sublevel set is already a ball.

Tests (10/10)

merge_captures_cross_terms (merged ≈600 not 400), count_sketch_estimates_f2, monitor_alert_threshold, allocate_p_higher_local_f2, sampling_var_budget, and geometric: silent_under_small_drift, triggers_when_drift_threatens_tau, stays_silent_then_resyncs (savings), alert_on_resync_over_tau.

Theory anchors

Cormode, "The continuous distributed monitoring model" (SIGMOD Record 2013); Sharfman–Schuster–Keren geometric monitoring; Cormode–Muthukrishnan–Yi distributed functional monitoring. Pairs with L1 per-key-freq allocation (#377).

Scope

Algorithmic core, pure + tested. Transport wiring (sketch in MonitorReport, C_ref broadcast, edge-side local safe-zone test, server.rs routing f2, control-plane functional: f2) is the integration follow-up.

🤖 Generated with Claude Code

zz_y and others added 3 commits June 16, 2026 12:25
Real distributed second-frequency-moment monitor — the L2 counterpart to the L1
slack-countdown coordinator. The hard part is that F2 does NOT merge linearly:
  F2(Σ f_i) = Σ F2(f_i) + 2 Σ_{i<j} ⟨f_i, f_j⟩   (cross terms)
so summing per-edge F2 is wrong. Fix (AMS / Cormode–Garofalakis): keep a LINEAR
AMS tug-of-war sketch Z = Σ g(x)f(x) (±1 hash) per edge — Z is linear in updates,
so Z_merged = Σ Z_i and E[Z_merged²] = F2(Σ f_i); squaring the MERGED sketch
recovers the cross terms automatically.

data_plane/src/monitor/f2.rs:
- AmsF2Sketch: update / linear merge / estimate_f2 (mean-of-Z² per group, median
  over s2 groups). s1=O(1/ε²) averaging, s2=O(log 1/δ) median.
- DistributedF2Monitor: per-edge sketches, merge-on-report, global F2̂, fires once
  at F2̂ ≥ (1−ε)τ.
- sampling_var_budget() = ε²·F2 — the L2 variance budget (ε·‖f‖₂)² for the SAME
  per-key p_i ∝ √(f_i/rate_i) allocation (sampling_alloc unchanged; only the
  norm in the budget differs from L1's (ε·τ)²).

5 unit tests incl. merge_captures_cross_terms (merged F2̂≈600 not 400) — proving
the non-linear merge is handled. Pure, no I/O.

Scope: this is the data-plane algorithmic core (the novel/hard part), fully
tested. End-to-end transport — extending MonitorReport to carry the AMS sketch,
the edge (Go) computing it, server.rs routing F2 monitors, and the control-plane
emitting a `functional: f2` — is the integration follow-up.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Switch the distributed-F2 estimator from AMS tug-of-war to a Count-Sketch
(d rows × w buckets, ±1 sign), matching ASAP's warm-tier sketch family and the
UnivMon/Cormode-Garofalakis line. Same linear-merge-captures-cross-terms property
(C_merged = Σ C_i, F2̂ = median_r Σ_b C[r][b]²). Hashing = murmur3 fmix64 with a
different seed per row and a different salt for bucket vs sign (engineering
approximation, like xxhash/murmur — not provably 4-wise independent).

DistributedF2Monitor now also does the L2 coordinated-sampling allocation:
allocate_p() with freq_i = each edge's LOCAL F2̂_i (from its own sketch),
rate_i = reported rate, var_budget = ε²·F2̂_global — so p_i ∝ √(F2̂_i/rate_i)
(an edge carrying more L2 mass keeps a higher p). Mirrors the L1
coordinator::allocate_p with the L2 freq/budget.

Division of labour: EDGE maintains its local Count-Sketch (shared seeds) + rate
and ships (sketch, rate) per window; COORDINATOR merges linearly, estimates F2̂,
fires at (1−ε)τ, and allocates p_i. 6 unit tests incl. cross-term merge and
equal-rate-different-F2 allocation.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…CDM-F2)

Adds GeometricF2Monitor — the Sharfman–Schuster–Keren safe-zone layer that makes
distributed F2 monitoring communication-efficient and BREAKS the circularity
"need L2 to decide whether to send, but need the sketch to get L2": each site
runs a PURELY LOCAL test — does its drift ball stay inside the safe ball
B(0, √(d·τ))? — using only the last-broadcast reference C_ref and its OWN drift
ΔC_i, never the live global. A site ships its sketch ONLY when locally unsafe,
triggering a resync.

Monitored quantity ‖C‖₂² (E=d·F2) vs d·τ; convexity theorem: global C=(1/k)Σu_i
is in the convex hull of u_i=C_ref+k·ΔC_i, so all per-site bounding balls
⊆ B(0,R) ⇒ ‖C‖<R ⇒ F2<τ (no missed crossing). F2 is the clean case — its sublevel
set is already a ball (no covering spheres).

CountSketchF2 gains l2_norm_sq / minus / norm_sq_combo for the ball test. 4 new
tests: silent under small drift, trips on threatening drift, stays-silent-then-
resyncs (communication savings), alert on resync over τ. 10/10 f2 tests green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@zzylol zzylol changed the title feat(monitor): distributed L2 / F2 threshold monitoring (AMS, cross-term-correct) feat(monitor): communication-efficient distributed L2/F2 monitoring (Count-Sketch + geometric safe-zone) Jun 16, 2026
@zzylol
zzylol merged commit 2c11933 into main Jun 17, 2026
@zzylol
zzylol deleted the feat/l2-f2-distributed-monitor branch July 17, 2026 20:05
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