[improve][broker] Optimize AsyncTokenBucket overflow solution further to reduce fallback to BigInteger - #25269
Conversation
… to reduce fallback to BigInteger
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #25269 +/- ##
=============================================
+ Coverage 37.33% 72.60% +35.27%
- Complexity 13272 34441 +21169
=============================================
Files 1902 1959 +57
Lines 151358 155543 +4185
Branches 17252 17741 +489
=============================================
+ Hits 56502 112938 +56436
+ Misses 87162 33592 -53570
- Partials 7694 9013 +1319
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR further hardens AsyncTokenBucket’s overflow-safe arithmetic by caching pre-reduced rate parameters (rate and rate period) to reduce how often computations must fall back to BigInteger, which is especially relevant for very large byte-rate limits.
Changes:
- Introduce an internal cached
RateParametershelper that reduces(rate, ratePeriodNanos)by their highest common power of ten. - Route token-refill and throttling-duration calculations through the reduced parameters.
- Expand
AsyncTokenBucketTestcoverage with additional very-large rate inputs.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| pulsar-broker/src/main/java/org/apache/pulsar/broker/qos/AsyncTokenBucket.java | Adds cached reduced-rate parameters and uses them in refill/throttling calculations to reduce BigInteger fallback. |
| pulsar-broker/src/test/java/org/apache/pulsar/broker/qos/AsyncTokenBucketTest.java | Adds larger rate values to exercise overflow-safe paths at multi-GB/s scale. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
… to reduce fallback to BigInteger (apache#25269) (cherry picked from commit 4cbe124) (cherry picked from commit 9d8240f)
… to reduce fallback to BigInteger (apache#25269) (cherry picked from commit 4cbe124) (cherry picked from commit 9d8240f)
Motivation
#25262 added a solution to prevent overflow in token & duration calculations. The solution falls back to the usage of BigInteger for very large values. This PR introduces yet another optimization that reduces the need to fallback to BigInteger.
This would be relevant when using multi gigabyte byte rate limits.
Modifications
Documentation
docdoc-requireddoc-not-neededdoc-complete