You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "Savonitar (via GitHub)" <gi...@apache.org> on 2026/08/04 14:34:29 UTC
[PR] [FLINK-40326][core] Do not over-grant capacity in GatedRateLimiter [flink]
Savonitar opened a new pull request, #28920:
URL: https://github.com/apache/flink/pull/28920
<!--
*Thank you very much for contributing to Apache Flink - we are happy that you want to help us improve Flink. To help the community review your contribution in the best possible way, please go through the checklist below, which will get the contribution into a shape in which it can be best reviewed.*
*Please understand that we do not do this to make contributions to Flink a hassle. In order to uphold a high standard of quality for code contributions, while at the same time managing a large number of contributions, we need contributors to prepare the contributions well, and give reviewers enough contextual information for the review. Please also understand that contributions that do not follow this guide will take longer to review and thus typically be picked up with lower priority by the community.*
## Contribution Checklist
- Make sure that the pull request corresponds to a [JIRA issue](https://issues.apache.org/jira/projects/FLINK/issues). Exceptions are made for typos in JavaDoc or documentation files, which need no JIRA issue.
- Name the pull request in the form "[FLINK-XXXX] [component] Title of the pull request", where *FLINK-XXXX* should be replaced by the actual issue number. Skip *component* if you are unsure about which is the best component.
Typo fixes that have no associated JIRA issue should be named following this pattern: `[hotfix] [docs] Fix typo in event time introduction` or `[hotfix] [javadocs] Expand JavaDoc for PuncuatedWatermarkGenerator`.
- Fill out the template below to describe the changes contributed by the pull request. That will give reviewers the context they need to do the review.
- Make sure that the change passes the automated tests, i.e., `mvn clean verify` passes. You can set up Azure Pipelines CI to do that following [this guide](https://cwiki.apache.org/confluence/display/FLINK/Azure+Pipelines#AzurePipelines-Tutorial:SettingupAzurePipelinesforaforkoftheFlinkrepository).
- Each pull request should address only one issue, not mix up code from multiple issues.
- Each commit in the pull request has a meaningful commit message (including the JIRA id)
- Once all items of the checklist are addressed, remove the above text and this checklist, leaving only the filled out template below.
**(The sections below can be removed for hotfixes of typos)**
-->
## What is the purpose of the change
The decrement in acquire() was generalized from a constant 1 to numberOfEvents as part of FLIP-535, but the gate was left closing only at capacityLeft <= 0, so a cycle can admit more events than capacityPerCycle. The gate is now closed unless the capacity left covers the whole request.
## Brief change log
- Close the gate in GatedRateLimiter#acquire(int) unless the capacity left covers the whole request, rather than only once it has reached zero
- Reject a non-positive numberOfEvents
- Initialize gatingFuture eagerly, so notifyCheckpointComplete before the first acquire() no longer throws a NullPointerException
- Correct the class Javadoc
## Verifying this change
Added tests that prevent regression and verifies new change.
## Does this pull request potentially affect one of the following parts:
- Dependencies (does it add or upgrade a dependency): (no)
- The public API, i.e., is any changed class annotated with `@Public(Evolving)`: (yes, but Javadoc only )
- The serializers: (no, a transient modifier is dropped, but GatedRateLimiter does not implement Serializable (only RateLimiterStrategy does), so it had no effect.)
- The runtime per-record code paths (performance sensitive): (yes, acquire(int) is called once per input record when rate limiting is enabled.)
- Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn, ZooKeeper: (no)
- The S3 file system connector: (no)
## Documentation
- Does this pull request introduce a new feature? (no)
- If yes, how is the feature documented? (not applicable)
---
##### Was generative AI tooling used to co-author this PR?
<!--
If generative AI tooling has been used in the process of authoring this PR, please
change the checkbox below to `[X]` and replace the placeholder in the "Generated-by"
line with the tool name and version. Otherwise remove the "Generated-by" line.
See the ASF Generative Tooling Guidance for details:
https://www.apache.org/legal/generative-tooling.html
You are responsible for the quality and correctness of every change in this PR
regardless of the tooling used. Low-effort AI-generated PRs will be closed. See
AGENTS.md for the full guidance.
-->
- [ ] Yes (please specify the tool below)
Generated-by: [Tool Name and Version]
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-40326][core] Do not over-grant permits in GatedRateLimiter [flink]
Posted by "1996fanrui (via GitHub)" <gi...@apache.org>.
1996fanrui merged PR #28920:
URL: https://github.com/apache/flink/pull/28920
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-40326][core] Do not over-grant capacity in GatedRateLimiter [flink]
Posted by "flinkbot (via GitHub)" <gi...@apache.org>.
flinkbot commented on PR #28920:
URL: https://github.com/apache/flink/pull/28920#issuecomment-5180614583
<!--
Meta data
{
"version" : 1,
"metaDataEntries" : [ {
"hash" : "0988ec0f815b1af468a1d039cf2c543cb3aceeb1",
"status" : "UNKNOWN",
"url" : "TBD",
"triggerID" : "0988ec0f815b1af468a1d039cf2c543cb3aceeb1",
"triggerType" : "PUSH"
} ]
}-->
## CI report:
* 0988ec0f815b1af468a1d039cf2c543cb3aceeb1 UNKNOWN
<details>
<summary>Bot commands</summary>
The @flinkbot bot supports the following commands:
- `@flinkbot run azure` re-run the last Azure build
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-40326][core] Do not over-grant permits in GatedRateLimiter [flink]
Posted by "Savonitar (via GitHub)" <gi...@apache.org>.
Savonitar commented on PR #28920:
URL: https://github.com/apache/flink/pull/28920#issuecomment-5207432800
@1996fanrui thanks for the questions and feedback.
> Two questions:
> The gate now closes while capacity is still unused, so a cycle always emits less than capacityPerCycle and never reaches it — with capacityPerCycle=100 and 6 events per request, every cycle stops at 96.
1. Yes, it undershoots now instead of overshooting, but isn't that the direction a rate limiter should err in? With capacityPerCycle=100, a single acquire(1000) was granted immediately and in full before this PR, because `100 <= 0` is false. Also, doesn't it seem strange to use negative value for capacity(which can happen in pre-PR code)?
> A single request larger than the cycle capacity still exceeds it: with capacityPerCycle=100 and acquire(10000), the first cycle emits nothing and then every following checkpoint releases the whole 10000, since notifyCheckpointComplete resets capacityLeft and drops the negative balance.
2.That one is pre-existing, not introduced here: before the PR it produced [10000, 10000, ...], now it produces [0, 10000, ...].
So this is an iterative improvement rather than a complete fix, a strict cap would need a redesign. This PR fixes three separate things: the gate, an NPE when a checkpoint completes before the first acquire(), and a missing argument check. I'm happy to drop the gate change and keep the overshoot if you think that's better by design. WDYT?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-40326][core] Do not over-grant capacity in GatedRateLimiter [flink]
Posted by "1996fanrui (via GitHub)" <gi...@apache.org>.
1996fanrui commented on PR #28920:
URL: https://github.com/apache/flink/pull/28920#issuecomment-5197121612
Thanks for the fix. Two questions:
1. The gate now closes while capacity is still unused, so a cycle always emits less than `capacityPerCycle` and never reaches it — with `capacityPerCycle=100` and 6 events per request, every cycle stops at 96.
2. A single request larger than the cycle capacity still exceeds it: with `capacityPerCycle=100` and `acquire(10000)`, the first cycle emits nothing and then every following checkpoint releases the whole 10000, since `notifyCheckpointComplete` resets `capacityLeft` and drops the negative balance.
So we neither reach `capacityPerCycle` in the first case nor stay within it in the second. How do you think we should handle this?
Fine with me if this is the accepted behaviour.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org