Repository navigation
loadshed: add priority-aware shedding and query wiring - #947
rcohen2000 wants to merge 28 commits into
Conversation
c891eb2 to
4868c9a
Compare
|
This PR is being marked as stale because it has been open for 30 days with no activity. To rectify, you may do any of the following:
If no action is taken within 7 days, this PR will be closed. |
|
This PR was closed because it has been stale for 7 days with no activity. |
7a68a26 to
ccf3403
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## bwines/snake-22-02-codel #947 +/- ##
=========================================================
Coverage 70.07% 70.08%
=========================================================
Files 1614 1615 +1
Lines 217187 217250 +63
=========================================================
+ Hits 152197 152251 +54
- Misses 64990 64999 +9 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
27ef558 to
0ee2076
Compare
0ee2076 to
ad7cc1c
Compare
Co-Authored-By: Codex <svc-devxp-Codex@slack-corp.com> Signed-off-by: Ross Cohen <rcohen@slack-corp.com>
Co-Authored-By: Codex <svc-devxp-Codex@slack-corp.com> Signed-off-by: Ross Cohen <rcohen@slack-corp.com>
Co-Authored-By: Codex <svc-devxp-Codex@slack-corp.com> Signed-off-by: Ross Cohen <rcohen@slack-corp.com>
Co-Authored-By: Codex <svc-devxp-Codex@slack-corp.com> Signed-off-by: Ross Cohen <rcohen@slack-corp.com>
Co-Authored-By: Codex <svc-devxp-Codex@slack-corp.com> Signed-off-by: Ross Cohen <rcohen@slack-corp.com>
Co-Authored-By: Codex <svc-devxp-Codex@slack-corp.com> Signed-off-by: Ross Cohen <rcohen@slack-corp.com>
Remove transient formatting churn and keep the stress test on the private priority-aware pool path. Co-Authored-By: Codex <svc-devxp-Codex@slack-corp.com> Signed-off-by: Ross Cohen <rcohen@slack-corp.com>
Co-Authored-By: Codex <svc-devxp-Codex@slack-corp.com> Signed-off-by: Ross Cohen <rcohen@slack-corp.com>
Co-Authored-By: Codex <svc-devxp-Codex@slack-corp.com> Signed-off-by: Ross Cohen <rcohen@slack-corp.com> # Conflicts: # go/pools/smartconnpool/waitlist.go # go/pools/smartconnpool/waitlist_test.go
Signed-off-by: Brett Wines <bwines@slack-corp.com>
…ity-wiring # Conflicts: # go/pools/smartconnpool/stress_test.go # go/vt/vttablet/tabletserver/loadshed/snake_stats_test.go
Co-Authored-By: Codex <svc-devxp-Codex@slack-corp.com> Signed-off-by: Ross Cohen <rcohen@slack-corp.com>
…ity-wiring Signed-off-by: Brett Wines <bwines@slack-corp.com> # Conflicts: # go/vt/vttablet/tabletserver/loadshed/snake_stats_test.go
…ity-wiring Signed-off-by: Brett Wines <bwines@slack-corp.com>
Signed-off-by: Ross Cohen <rcohen@slack-corp.com> Co-Authored-By: Codex <svc-devxp-Codex@slack-corp.com>
Co-Authored-By: Codex <svc-devxp-Codex@slack-corp.com> Signed-off-by: Ross Cohen <rcohen@slack-corp.com>
…ity-wiring Signed-off-by: Brett Wines <bwines@slack-corp.com>
Co-Authored-By: Codex <svc-devxp-Codex@slack-corp.com> Signed-off-by: Ross Cohen <rcohen@slack-corp.com>
…ity-wiring Signed-off-by: Brett Wines <bwines@slack-corp.com> # Conflicts: # go/vt/vttablet/tabletserver/loadshed/codelq_test.go # go/vt/vttablet/tabletserver/loadshed/dequeue_shed_test.go # go/vt/vttablet/tabletserver/loadshed/snake.go
…ity-wiring Signed-off-by: Brett Wines <bwines@slack-corp.com>
…ity-wiring Signed-off-by: Brett Wines <bwines@slack-corp.com>
…ity-wiring Signed-off-by: Brett Wines <bwines@slack-corp.com>
Signed-off-by: Brett Wines <bwines@slack-corp.com>
Signed-off-by: Brett Wines <bwines@slack-corp.com>
…ity-wiring Co-Authored-By: Codex <svc-devxp-Codex@slack-corp.com> Signed-off-by: Ross Cohen <rcohen@slack-corp.com>
Signed-off-by: Brett Wines <bwines@slack-corp.com>
ad7cc1c to
f1e51cd
Compare
tanjinx
left a comment
There was a problem hiding this comment.
Priority plumbing and the O(1) droppable index look correct; three design and observability points to weigh, nothing blocking.
0 Should fix, 3 Consider, 2 Nit.
What I verified, by reading the diff and the head files at f1e51cd (no tests run locally):
- Every queue removal path (
Dequeue,Cancel,CancelMatching,Drain, enqueue and timer drops) goes throughlockedRemove, so the index stays in lockstep withdroppableLen. - On the query path, only
getConnandStatefulConnectionPool.NewConnreach Snake-enabled pools; the otherGetcallers (priority 0) are startup-only (inferred from upstream call sites). - The expire-worker early return only skips the scan when
tryReturnAnyConnwould have had nothing to hand over. - This replaces the O(n)
lockedFindDroppablescan from my #943 nit. The backstop re-arm andcfg.Mode()underwl.muthreads on #943 still apply here.
CI at f1e51cd: the required Unit Test (mysql80) failed in go/vt/vtgate/schema (TestTrackerNoLock) and vttablet/tabletmanager/vreplication (vplayer tests), packages this PR doesn't touch. Unit Test (mysql84) and Unit Test (Race) passed at the same head, so it looks unrelated (inferred). Optional Code Coverage and the Query Serving (Queries) upgrade/downgrade job (vtgate_queries_timeout) also failed.
🤖 Written by Speck, Slack's coding agent, on the author's behalf
💬 Code Channel: Private channel
| } else { | ||
| var newlyDropped []*list.Element[waiter[C]] | ||
| request, newlyDropped = wl.snake.Enqueue(elem) | ||
| request, newlyDropped = wl.snake.Enqueue(elem, priority) |
There was a problem hiding this comment.
Consider: Priority 0 now reaches Snake as undroppable, and in ModeEnabled the waiter cap is off (L107, L127). Before this PR every new waiter was droppable, so CoDel bounded the queue once the cap was lifted. Now any PRIORITY=0 query, and every tx-pool waiter on a tablet running --tx-throttler-default-priority=0 (the tx pools inherit that flag at connpool/pool.go L54), queues with neither a cap nor shedding, bounded only by its context deadline. 0 is also the tx throttler's never-throttle value, so callers who set it to avoid throttling now skip shedding and the cap too (inferred). Consider keeping the waiter cap for undroppable waiters in enabled mode, or giving the tx pools their own default flag like --loadshed-oltp-read-default-priority.
🤖 Written by Speck, Slack's coding agent, on the author's behalf
💬 Code Channel: Private channel
| priority = s.cfg.DefaultPriority | ||
| } | ||
| if recordAcquire && s.acquireByPriority != nil { | ||
| s.acquireByPriority.Add([]string{strconv.Itoa(priority)}, 1) |
There was a problem hiding this comment.
Consider: This runs under wl.mu on every Snake enqueue, and CountersWithMultiLabels.Add takes the counter's own mutex and writes a map (go/stats/counters.go L50-L54). Every scrape's Counts() copies that map under the same mutex, so a scrape can stall enqueues during overload. strconv.Itoa also allocates for 100, the OLTP-read default, since Go only caches 0-99. A [sqlparser.MaxPriorityValue + 1]atomic.Int64 per metric, exported with NewCountersFuncWithMultiLabels, keeps this lock-free; the same applies to shedByPriority at L307. Not benchmarked (inferred).
🤖 Written by Speck, Slack's coding agent, on the author's behalf
💬 Code Channel: Private channel
| return s.ShedCount() | ||
| }) | ||
| s.shedByPriority = exporter.NewCountersWithMultiLabels(prefix+"ShedByPriority", "Cumulative requests shed by the Snake load shedder, labeled by query priority (\"0\" undroppable, \"1\" most important .. \"100\" least); sum equals ShedCount", []string{"priority"}) | ||
| s.acquireByPriority = exporter.NewCountersWithMultiLabels(prefix+"AcquireByPriority", "Cumulative Acquire attempts (offered load) labeled by query priority (\"0\" undroppable, \"1\" most important .. \"100\" least); ShedByPriority/AcquireByPriority is the per-priority shed rate", []string{"priority"}) |
There was a problem hiding this comment.
Consider: This counter isn't offered load. It's bumped only in Snake.enqueue (snake.go L130-L131), which runs after get/getWithSetting found no idle or new connection, and only while the pool is in shadow or enabled mode (waitlist.go L137-L141). Requests served on the fast path never count, so ShedByPriority / AcquireByPriority is the shed rate among requests that queued, which overstates the per-priority shed rate of traffic. Rewording this help text and the field comment at snake.go L60-L63 (or renaming to something like QueuedByPriority) keeps dashboards honest; if offered load is the goal, count in ConnPool.GetWithPriority instead.
🤖 Written by Speck, Slack's coding agent, on the author's behalf
💬 Code Channel: Private channel
| // bucket and list node on the request for O(1) removal. Must not be called for | ||
| // an undroppable request. | ||
| func (idx *droppableIndex[T]) insert(req *Request[T]) { | ||
| b := req.priority - 1 |
There was a problem hiding this comment.
Nit: insert trusts that the priority is 1-100. Snake.enqueue validates the caller's value but substitutes s.cfg.DefaultPriority unchecked (snake.go L128). Verify covers today's two flags, but a SnakeConfig built anywhere else with an out-of-range default panics here while wl.mu is held, and a negative one also counts as droppable because isDroppable is != 0. Separately, occ [2]uint64 covers only 128 buckets. A range check in NewSnake plus a compile-time guard such as const _ = uint(128 - numPriorityBuckets) would pin both.
🤖 Written by Speck, Slack's coding agent, on the author's behalf
💬 Code Channel: Private channel
| return wl.numWaiting() == 7 | ||
| }, time.Second, time.Millisecond) | ||
|
|
||
| time.Sleep(2 * time.Millisecond) |
There was a problem hiding this comment.
Nit: This test passes only if the waiters all enqueue within testPoolConfig's 1ms interval. Once five droppable waiters are queued, any enqueue more than 1ms after the first droppable one makes lockedEnqueueAdvance shed on the spot (whichever is lowest at that moment, possibly 60 or 70), and the numWaiting() == 7 wait above never succeeds. Race CI passed at this head, so it's rare (inferred). CLAUDE.md asks for assert.Eventually over sleeps, but polling runDropTimer() doesn't work today: a fire before dropNextNs disarms the backstop without re-arming (the #943 re-arm thread). A per-test interval well above goroutine start skew, for example a field on testPoolConfig, would close the window.
🤖 Written by Speck, Slack's coding agent, on the author's behalf
💬 Code Channel: Private channel
👋🏻 This PR description is human-written.
Background / Why?
Snake must preserve Vitess query priorities so overload sheds less important work before latency-sensitive work. Direct vttablet callers can bypass VTGate validation, and malformed priorities previously reached a fixed 100-bucket index, so this PR validates values at the tablet boundary and falls back to each pool's configured default if an invalid value nevertheless reaches Snake. Configured defaults are checked at startup even when the transaction throttler is disabled, preventing a later runtime enablement from exposing an invalid priority. Internal 2PC metadata transactions need to complete during overload to resolve and clean up prepared transactions, so those specific acquisitions explicitly use the existing undroppable priority. Equal-priority requests remain FIFO, while the bucketed index selects the highest numeric droppable priority in constant time.
Testing
new unit tests covering priority parsing, bounds, configured-default fallback, propagation, ordering, bucket-index behavior, undroppable requests, and metrics
AI assisted with development. Every line of code was either written by or carefully reviewed by me :)