feat(api): add configurable blocking mode for API rate limiters#6761
Merged
lvs0075 merged 1 commit intoMay 12, 2026
Conversation
- Add `rate.limiter.apiNonBlocking` switch (default false). When off, callers wait for a permit; when on, they reject immediately and shed load. - Wire the switch through `RateLimiterConfig` → `Args` → `CommonParameter`; update `reference.conf` / `config.conf`. - Add blocking `acquire()` paths on `IRateLimiter`, `GlobalRateLimiter`, and `QpsStrategy` / `IPQpsStrategy` / `GlobalPreemptibleStrategy`. Only the semaphore-based strategy is bounded (2s); the QPS-based paths use unbounded Guava `RateLimiter.acquire()`. - Introduce `acquirePermit()` dispatcher (default method on `IRateLimiter`; static on `GlobalRateLimiter`) that picks blocking vs non-blocking based on the switch. - Swap `tryAcquire` → `acquirePermit` at the `RateLimiterServlet` and `RateLimiterInterceptor` call sites; preserve per-endpoint-before-global ordering to avoid consuming global quota on per-endpoint rejection. - Extract `loadIpLimiter()` in `GlobalRateLimiter` and `loadLimiter()` in `IPQpsStrategy` to share cache+exception handling between `tryAcquire` and `acquire`. - Add unit tests covering dispatcher routing (both directions), acquire IP-before-global ordering, and IP-loader-failure fail-closed behaviour.
halibobo1205
approved these changes
May 12, 2026
0xbigapple
approved these changes
May 12, 2026
warku123
added a commit
to warku123/java-tron
that referenced
this pull request
May 12, 2026
… and tronprotocol#6761 (rate-limiter blocking mode)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Add configurable blocking mode for API rate limiters.
rate.limiter.apiNonBlockingswitch (default false). When off, callers wait for a permit; when on, they reject immediately and shed load.RateLimiterConfig→Args→CommonParameter; updatereference.conf/config.conf.acquire()paths onIRateLimiter,GlobalRateLimiter, andQpsStrategy/IPQpsStrategy/GlobalPreemptibleStrategy. Only the semaphore-based strategy is bounded (2s); the QPS-based paths use unbounded GuavaRateLimiter.acquire().acquirePermit()dispatcher (default method onIRateLimiter; static onGlobalRateLimiter) that picks blocking vs non-blocking based on the switch.tryAcquire→acquirePermitat theRateLimiterServletandRateLimiterInterceptorcall sites; preserve per-endpoint-before-global ordering to avoid consuming global quota on per-endpoint rejection.loadIpLimiter()inGlobalRateLimiterandloadLimiter()inIPQpsStrategyto share cache+exception handling betweentryAcquireandacquire.Why are these changes required?
This PR has been tested by:
Follow up
Extra details