Skip to content

Conversation

@nickvanw
Copy link
Collaborator

Description

This PR implements #18786 and adds a cell-agnostic "random" tablet load balancer algorithm.

At PlanetScale, we often find that traffic into VTGates is very uneven - either because of individual applications that might be single-AZ, a lack of AZ overlap, or a specific piece of infrastructure is singular, but produces a lot of load on replicas.

When this happens, it ends up that an individual cell's worth of VTTablets can get very overloaded, causing humans to hae to step in and manually scale components, etc. If the particular overloaded cell changes, it requires continued manual access.

Many times, we'd rather pay for the cross-zone latency and bandwidth costs and just spread it evenly across every replica. That is what this PR implements.

Related Issue(s)

RFC: #18786

Checklist

  • "Backport to:" labels have been added if this change should be back-ported to release branches
  • If this change is to be back-ported to previous releases, a justification is included in the PR description
  • Tests were added or are not required
  • Did the new or modified tests pass consistently locally and on CI?
  • Documentation was added or is not required

AI Disclosure

This PR was written by a human and Claude Code - all changes were reviewed by a human.

@vitess-bot
Copy link
Contributor

vitess-bot bot commented Oct 23, 2025

Review Checklist

Hello reviewers! 👋 Please follow this checklist when reviewing this Pull Request.

General

  • Ensure that the Pull Request has a descriptive title.
  • Ensure there is a link to an issue (except for internal cleanup and flaky test fixes), new features should have an RFC that documents use cases and test cases.

Tests

  • Bug fixes should have at least one unit or end-to-end test, enhancement and new features should have a sufficient number of tests.

Documentation

  • Apply the release notes (needs details) label if users need to know about this change.
  • New features should be documented.
  • There should be some code comments as to why things are implemented the way they are.
  • There should be a comment at the top of each new or modified test to explain what the test does.

New flags

  • Is this flag really necessary?
  • Flag names must be clear and intuitive, use dashes (-), and have a clear help text.

If a workflow is added or modified:

  • Each item in Jobs should be named in order to mark it as required.
  • If the workflow needs to be marked as required, the maintainer team must be notified.

Backward compatibility

  • Protobuf changes should be wire-compatible.
  • Changes to _vt tables and RPCs need to be backward compatible.
  • RPC changes should be compatible with vitess-operator
  • If a flag is removed, then it should also be removed from vitess-operator and arewefastyet, if used there.
  • vtctl command output order should be stable and awk-able.

@vitess-bot vitess-bot bot added NeedsBackportReason If backport labels have been applied to a PR, a justification is required NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsIssue A linked issue is missing for this Pull Request NeedsWebsiteDocsUpdate What it says labels Oct 23, 2025
@github-actions github-actions bot added this to the v24.0.0 milestone Oct 23, 2025
@nickvanw nickvanw marked this pull request as draft October 23, 2025 09:03
@nickvanw nickvanw removed NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsIssue A linked issue is missing for this Pull Request NeedsBackportReason If backport labels have been applied to a PR, a justification is required labels Oct 23, 2025
@arthurschreiber
Copy link
Member

Neat! ❤️

@nickvanw nickvanw force-pushed the nickvanw/random-tablet-balancer branch from ef98dfe to 7679c95 Compare October 25, 2025 12:47
@nickvanw nickvanw force-pushed the nickvanw/random-tablet-balancer branch from 7679c95 to d127f64 Compare October 25, 2025 13:13
@codecov
Copy link

codecov bot commented Oct 25, 2025

Codecov Report

❌ Patch coverage is 67.56757% with 36 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.72%. Comparing base (dbcfdd9) to head (b142edb).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
go/vt/vtgate/balancer/random_balancer.go 65.85% 14 Missing ⚠️
go/vt/vtgate/balancer/balancer.go 71.79% 11 Missing ⚠️
go/vt/vtgate/tabletgateway.go 66.66% 10 Missing ⚠️
go/vt/vtgate/vtgate.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #18787      +/-   ##
==========================================
+ Coverage   69.70%   69.72%   +0.01%     
==========================================
  Files        1607     1608       +1     
  Lines      214608   214698      +90     
==========================================
+ Hits       149592   149689      +97     
+ Misses      65016    65009       -7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@nickvanw nickvanw marked this pull request as ready for review October 25, 2025 13:44
@nickvanw
Copy link
Collaborator Author

I noticed the previous strategy wasn't covered by end to end tests, so I'm going to write up a suite of them that should cover everything.

@nickvanw nickvanw force-pushed the nickvanw/random-tablet-balancer branch from 238e02c to 617520c Compare October 30, 2025 20:42
@mattlord mattlord self-requested a review October 30, 2025 20:46
@nickvanw nickvanw force-pushed the nickvanw/random-tablet-balancer branch from 617520c to 74072b5 Compare October 30, 2025 20:50
Signed-off-by: Nick Van Wiggeren <[email protected]>
@nickvanw nickvanw force-pushed the nickvanw/random-tablet-balancer branch from c593a74 to 02a9ecb Compare October 30, 2025 21:32
Copy link
Member

@mattlord mattlord left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking good! Just some minor comments. Happy to chat about them. I can then go through the tests.

@nickvanw nickvanw force-pushed the nickvanw/random-tablet-balancer branch from 0871339 to 3128164 Compare October 31, 2025 17:14
@nickvanw nickvanw force-pushed the nickvanw/random-tablet-balancer branch from 3128164 to 6c8590e Compare October 31, 2025 17:24
Copy link
Member

@mattlord mattlord left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! My only issues are with the tests as I think they will prove to be flaky over time. Let me know what you think about my comments so far, as I think they will apply throughout the others as well.

cell1Count := 0
cell2Count := 0
for _, tablet := range allTablets {
if tablet.Type != "replica" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would recommend using topodata.TabletType_REPLICA.String() and similar throughout.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like there's a caps vs lowercase mixup, so I added a test-level variable that should work

Signed-off-by: Nick Van Wiggeren <[email protected]>
@nickvanw
Copy link
Collaborator Author

@mattlord thanks for the reviews! I've cleaned up the test suite significantly - there's no more time.Sleep present anywhere, and many things are broken out into helper methods so it should be straightforward to see what we're doing.

I think I've addressed all of the naming feedback as well, but let me know if you think there's anything else missing!

Signed-off-by: Nick Van Wiggeren <[email protected]>
@nickvanw nickvanw force-pushed the nickvanw/random-tablet-balancer branch from b80e217 to 0db6fb6 Compare October 31, 2025 21:57
Copy link
Member

@mattlord mattlord left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work on this, @nickvanw ! I had a couple of very minor comments that you can deal with as you choose.

@nickvanw
Copy link
Collaborator Author

Thanks for the further feedback @mattlord! All accepted in 3246c08 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants