Skip to content

Shard rate limiters and reuse broadcast scratch to cut worker lock contention#151

Merged
kwsantiago merged 3 commits into
mainfrom
fix/worker-lock-contention
Jul 12, 2026
Merged

Shard rate limiters and reuse broadcast scratch to cut worker lock contention#151
kwsantiago merged 3 commits into
mainfrom
fix/worker-lock-contention

Conversation

@wksantiago

@wksantiago wksantiago commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Fixes #152. Shard rate limiters and reuse broadcast scratch to cut worker lock contention.

@coderabbitai

coderabbitai Bot commented Jul 12, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@kwsantiago, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 30 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 0da50d6b-a91b-4cd7-bd6c-a69eaabccd33

📥 Commits

Reviewing files that changed from the base of the PR and between 666f059 and 06fd4a5.

📒 Files selected for processing (3)
  • src/main.zig
  • src/rate_limiter.zig
  • src/subscriptions.zig

Walkthrough

The rate limiters now use 16 independently locked shards for bucket operations and cleanup. Subscription matching reuses thread-local pending-write and deduplication containers instead of allocating them per broadcast.

Changes

Rate limiter sharding

Layer / File(s) Summary
Connection limiter shard operations
src/rate_limiter.zig
ConnectionLimiter routes per-IP checks, updates, removals, cleanup, and statistics through shard-local mutexes and maps.
Event limiter shard operations
src/rate_limiter.zig
EventRateLimiter applies token-bucket updates and cleanup per shard, with test helpers aggregating state across shards. Tests use those helpers for cleanup assertions.

Subscription matching scratch reuse

Layer / File(s) Summary
Reusable matching state
src/subscriptions.zig
forEachMatching clears and reuses thread-local pending-write and deduplication containers across calls.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

  • privkeyio/wisp#79: Both changes modify EventRateLimiter bucket storage and token-bucket cleanup behavior.

Poem

A rabbit counts shards in a moonlit array,
While buckets hop safely through locks on their way.
Broadcasts reuse scratch with a swift little cheer,
No fresh lists to nibble through year after year.
Thump-thump, the limiters and messages run bright!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the two main changes: sharding rate limiters and reusing broadcast scratch to reduce contention.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/worker-lock-contention

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@kwsantiago
kwsantiago merged commit e91931d into main Jul 12, 2026
4 checks passed
@kwsantiago
kwsantiago deleted the fix/worker-lock-contention branch July 12, 2026 15:59
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.

Worker-pool lock/allocator contention burns ~2 cores under multi-client load (separate from #145)

2 participants