Commit 9d124ef
authored
feat(bigtable): add PeakEwma continuous time-decay latency tracker (#20187)
## Summary
Adds `PeakEwma`, a thread-safe continuous-time exponentially-weighted
moving average of latency samples. The upcoming AFE picker (Session
subsystem) uses one instance per bucket to score candidates; landing the
type standalone lets it merge ahead of its consumers.
- **`peak_ewma.go`** — `PeakEwma` struct, `NewPeakEwma(tau)`,
`NewPeakEwmaSeeded(tau, seed)`, `Update(latency)`, `Value()`. Decay
weight is `e^(-dt/tau)` computed on every Update. First Update snaps
value to the sample; subsequent updates blend prior and new
proportionally.
- **`NewPeakEwmaSeeded`** — Java parity: `SessionList.java` seeds
transport at 500µs and e2e at 1ms so a brand-new AFE doesn't win the
least-latency picker by looking free-cost. The seed is authoritative
only until the first `Update`.
No callers on `main` yet — follow-up PRs for the AFE picker and
`sessionList` will consume it.
## Test plan
- [x] `go build ./bigtable/...`
- [x] `go test ./bigtable/internal/transport/ -run '^TestPeakEwma'
-count=10 -race` — passes (1.6s)
- [x] `gofmt -l bigtable/internal/transport/peak_ewma*.go` — clean
- [x] `go vet ./bigtable/internal/transport/` — clean
Test coverage:
- Unseeded / seeded initial `Value()`
- First `Update` overrides the seed (pins the documented behavior)
- Constant-sample invariant — `w*L + (1-w)*L == L` for any weight, so
the EWMA is exact on a flat stream
- Convex-combination bound — Value stays within `[min, max]` of samples
seen
- `Value()` is a pure read (no state mutation)
- Wide-gap dominance — `dt >> tau` ⇒ weight → 0 ⇒ Value tracks the
newest sample (skipped under `-short`)
- Mutex race check with mixed reader/writer goroutines (meaningful under
`-race`)1 parent 02e3c6d commit 9d124ef
2 files changed
Lines changed: 402 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
0 commit comments