Skip to content

Add adjustable refill rate to RotatingTokenBucketLimiter#36

Open
parsnips wants to merge 3 commits intowebriots:mainfrom
parsnips:adjustable-rotating-rate
Open

Add adjustable refill rate to RotatingTokenBucketLimiter#36
parsnips wants to merge 3 commits intowebriots:mainfrom
parsnips:adjustable-rotating-rate

Conversation

@parsnips
Copy link
Copy Markdown

@parsnips parsnips commented Mar 28, 2026

Summary

  • add SetRefillRate and RefillRate to RotatingTokenBucketLimiter
  • preserve existing bucket state while updating refill and rotation timing atomically
  • add regression coverage for validation, preserved state, faster/slower refill behavior, and updated rotation intervals

Downstream Context

  • parsnips/spreader uses this to split one global scheduling rate across a changing number of publishers in a distributed system
  • the scheduler keeps token weight fixed at 255 and adjusts only refill rate so counts above 255 still preserve the intended targetRate / publisherCount share
  • rebuilding the limiter on each publisher-count change reset bucket state and could reopen already-consumed capacity; in-place refill updates avoid that while keeping the rotating collision-resistant behavior
  • spreader is currently using this via a temporary replace to the forked branch and has regression coverage for the consumed-capacity case that motivated the change

Testing

  • go test ./...

@parsnips
Copy link
Copy Markdown
Author

The failing format job is not a formatting issue.

The workflow runs on pull_request_target and then does:

- uses: actions/checkout@v4
  with:
    ref: ${{ github.head_ref }}

For this PR, github.head_ref is adjustable-rotating-rate, but the checkout target is webriots/rate, so Actions is trying to fetch webriots/rate:adjustable-rotating-rate instead of parsnips/rate:adjustable-rotating-rate. The run fails during git fetch before gofumpt ever runs.

The branch is already pushed here: parsnips/rate:adjustable-rotating-rate.

A minimal fix is to check out the PR head repo explicitly, e.g.:

- uses: actions/checkout@v4
  with:
    repository: ${{ github.event.pull_request.head.repo.full_name }}
    ref: ${{ github.event.pull_request.head.ref }}

I verified locally that go mod tidy, gofumpt -l -w ., and go test ./... all pass on this branch.

parsnips added a commit to parsnips/spreader that referenced this pull request Mar 28, 2026
Depends on webriots/rate#36 for RotatingTokenBucketLimiter.SetRefillRate.
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