Skip to content

feat(api): add configurable blocking mode for API rate limiters#6761

Merged
lvs0075 merged 1 commit into
tronprotocol:release_v4.8.2from
xxo1shine:feat/ratelimiter-configurable-blocking-mode
May 12, 2026
Merged

feat(api): add configurable blocking mode for API rate limiters#6761
lvs0075 merged 1 commit into
tronprotocol:release_v4.8.2from
xxo1shine:feat/ratelimiter-configurable-blocking-mode

Conversation

@xxo1shine
Copy link
Copy Markdown
Collaborator

What does this PR do?

Add configurable blocking mode for API rate limiters.

  • 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 RateLimiterConfigArgsCommonParameter; 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 tryAcquireacquirePermit 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.

Why are these changes required?

This PR has been tested by:

  • Unit Tests
  • Manual Testing

Follow up

Extra details

- 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 halibobo1205 added the topic:api rpc/http related issue label May 12, 2026
@halibobo1205 halibobo1205 added this to the GreatVoyage-v4.8.2 milestone May 12, 2026
@lvs0075 lvs0075 requested a review from halibobo1205 May 12, 2026 06:16
Copy link
Copy Markdown
Collaborator

@waynercheung waynercheung left a comment

Choose a reason for hiding this comment

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

LGTM

@lvs0075 lvs0075 merged commit 5f7eeca into tronprotocol:release_v4.8.2 May 12, 2026
11 checks passed
warku123 added a commit to warku123/java-tron that referenced this pull request May 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic:api rpc/http related issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants