feat(monitor): communication-efficient distributed L2/F2 monitoring (Count-Sketch + geometric safe-zone) - #378
Merged
Merged
Conversation
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>
This was referenced Jun 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 rowC[r][b] = Σ_{x:h_r(x)=b} s_r(x) f(x)is linear in updates, soC_merged = Σ_i C_iandΣ_b C_merged[r][b]²estimatesF2(Σ_i f_i)— squaring the merged sketch recovers the cross terms.CountSketchF2—drows ×wbuckets, ±1 sign;update/ linearmerge/estimate_f2(median over rows ofΣ_b C[r][b]²);w=O(1/ε²),d=O(log 1/δ). Hashing = murmur3fmix64, different seed per row + different salt for bucket vs sign.DistributedF2Monitor— merges per-edge sketches, estimates globalF2̂, fires atF2̂ ≥ (1−ε)τ, and does the L2 coordinated-sampling allocationp_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:B(C_ref + (k/2)ΔC_i, (k/2)‖ΔC_i‖)stay inside the safe ballB(0, √(d·τ))? — using only the last-broadcastC_refand its own drift, never the live 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_refbroadcast, edge-side local safe-zone test,server.rsroutingf2, control-planefunctional: f2) is the integration follow-up.🤖 Generated with Claude Code