Skip to content

[fix][broker] Unthrottle producers immediately when publish rate limiting is disabled - #25502

Merged
thetumbled merged 6 commits into
apache:masterfrom
thetumbled:fix/publish-rate-disable-immediate-unthrottle
Apr 15, 2026
Merged

[fix][broker] Unthrottle producers immediately when publish rate limiting is disabled#25502
thetumbled merged 6 commits into
apache:masterfrom
thetumbled:fix/publish-rate-disable-immediate-unthrottle

Conversation

@thetumbled

@thetumbled thetumbled commented Apr 9, 2026

Copy link
Copy Markdown
Member

Motivation

When publish rate limiting is disabled (for example by clearing the publish rate policy so update(null) is called), token buckets are nulled out immediately, but producers that were already throttled could remain blocked until a previously scheduled unthrottle task ran. That delayed task may have been scheduled with a very long wait time when the token bucket was deeply depleted, so disabling the limit in configuration did not restore traffic quickly. This change triggers the existing lock-free unthrottle path right away after disablement when an executor was already cached from a prior throttle on this limiter.

Modifications

  • In PublishRateLimiterImpl, cache the ScheduledExecutorService used when scheduling unthrottleQueuedProducers after the first throttling event on this limiter instance.
  • When update(PublishRate) is called with a null PublishRate (rate limiting disabled), call scheduleUnthrottling(cachedExecutor, 0) so queued producers are processed without waiting on the old delayed task.

Verifying this change

  • Make sure that the change passes the CI checks.

(Please pick either of the following options)

This change is a trivial rework / code cleanup without any test coverage.

Does this pull request potentially affect one of the following parts:

If the box was checked, please highlight the changes

  • Dependencies (add or upgrade a dependency)
  • The public API
  • The schema
  • The default values of configurations
  • The threading model
  • The binary protocol
  • The REST endpoints
  • The admin CLI options
  • The metrics
  • Anything that affects deployment

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR ensures producers are unthrottled immediately when publish rate limiting is disabled, avoiding long waits from previously scheduled delayed unthrottle tasks.

Changes:

  • Cache the ScheduledExecutorService used for unthrottling after the first throttling event.
  • When update(null) disables rate limiting, trigger unthrottling immediately (0 delay) using the cached executor.

@liangyepianzhou

liangyepianzhou commented Apr 10, 2026

Copy link
Copy Markdown
Contributor
The scenario is valid, but the fix needs further evaluation. The root cause is that disabling rate limiting should **directly signal** throttled producers to be released, rather than waiting for the next scheduled cycle — i.e., the `disable` semantic itself should trigger an immediate (synchronous or async) unthrottle.

The current fix, via update(null), appears to work around the root cause by adding an operational workaround rather than addressing the underlying code defect. This may fail to resolve the fundamental issue, and worse, increases cognitive overhead for users who need to understand why an extra update(null) call is necessary.

Sorry, the code version I was looking at doesn't seem to be the latest.

@lhotari

lhotari commented Apr 10, 2026

Copy link
Copy Markdown
Member

That delayed task may have been scheduled with a very long wait time when the token bucket was deeply depleted,

@thetumbled did the problem happen also with the fix in #25262 and #25269?

@thetumbled

Copy link
Copy Markdown
Member Author

That delayed task may have been scheduled with a very long wait time when the token bucket was deeply depleted,

@thetumbled did the problem happen also with the fix in #25262 and #25269?

We haven't encountered this problem in our production environment yet. Since the bucket value is allowed to be negative, I am concerned that the producer may get stuck for a long time. We need a way to disable the throttling feature as quickly as possible.

@lhotari lhotari left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, a few comments to address.

@liangyepianzhou

Copy link
Copy Markdown
Contributor

Maybe a test should be added to verify that the fix actually works. Otherwise, there's no way to fully confirm whether issues similar to #25502 (comment) still exist — the scope of manual review is always limited.

@thetumbled

Copy link
Copy Markdown
Member Author

Maybe a test should be added to verify that the fix actually works. Otherwise, there's no way to fully confirm whether issues similar to #25502 (comment) still exist — the scope of manual review is always limited.

I will add one later.

@thetumbled

Copy link
Copy Markdown
Member Author

Tests have been added. You can comment out the call to scheduleImmediateUnthrottling(); to verify the original behavior, and the test will output an error. @liangyepianzhou
image

@thetumbled
thetumbled merged commit 85937d8 into apache:master Apr 15, 2026
79 of 82 checks passed
@lhotari lhotari added this to the 4.3.0 milestone Apr 21, 2026
lhotari pushed a commit that referenced this pull request Apr 21, 2026
…ting is disabled (#25502)

Co-authored-by: fengwenzhi <fengwenzhi.max@bigo.sg>
(cherry picked from commit 85937d8)
lhotari pushed a commit that referenced this pull request Apr 21, 2026
…ting is disabled (#25502)

Co-authored-by: fengwenzhi <fengwenzhi.max@bigo.sg>
(cherry picked from commit 85937d8)
nodece pushed a commit to ascentstream/pulsar that referenced this pull request May 27, 2026
…ting is disabled (apache#25502)

Co-authored-by: fengwenzhi <fengwenzhi.max@bigo.sg>
(cherry picked from commit 85937d8)
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.

5 participants