-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[KafkaIO] Fix average record size data race and backlog estimation #34165
base: master
Are you sure you want to change the base?
[KafkaIO] Fix average record size data race and backlog estimation #34165
Conversation
Checks are failing. Will not request review until checks are succeeding. If you'd like to override that behavior, comment |
Run Spotless PreCommit |
Assigning reviewers. If you would like to opt out of this review, comment R: @kennknowles for label java. Available commands:
The PR bot will only process comments in the main thread (not review comments). |
52e2c5f
to
ab5b88d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy for the improvement. I may be misunderstanding what is strictly necessary to make your changes work as intended but TL;DR the inheritance all seems extraneous - one of them seems like inlining is equivalent and clearer, while the other seems like it is more clearly expressed as a field.
* limitations under the License. | ||
*/ | ||
|
||
plugins { id 'org.apache.beam.module' } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use build.gradle.kts
for new files
*/ | ||
@SuppressFBWarnings("UUF_UNUSED_FIELD") | ||
private static class MovingAvgPadding { | ||
byte p000, p001, p002, p003, p004, p005, p006, p007; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this a reaction to a measured slowdown? I'm not like super opposed to having something like this, but I expect it's relevance and effectiveness to wane as the codebase evolves, unless we have some fairly deep and clear understanding of exactly what needs to be maintained.
|
||
// The accumulator's fields should be padded to at least 128 bytes (at least 1 or 2 | ||
// cache lines). | ||
private static class MovingAvgFields extends MovingAvgPadding { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the padding not just inlined here? It would be clearer what is going on and saves a layer of inheritance.
* Sanity of visibility is only useful when the writer thread changes since avg is the only field that can be shared between multiple concurrent threads. | ||
*/ | ||
@SuppressFBWarnings("UUF_UNUSED_FIELD") | ||
public static final class MovingAvg extends MovingAvgFields { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This class should simply have a private MovingAvgFields
member.
return Double.longBitsToDouble(avg); | ||
} | ||
|
||
protected void setAvg(final double value) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just make these package-private and call them from the MovingAvg class. (see below: use a field instead of inheritance)
The offset gap ratio may artificially shrink the backlog if consumers can't catch up to the tail of an expiring topic. This may cause runners to trigger a downscaling event which worsens the issue.
MovingAvg has been modified to atomically write the accumulated state since concurrent normal loads/stores of longs/doubles may tear. The numUpdates field is only used by the writer and can be kept as non-volatile, but the update method ensures that normal loads/stores on numUpdates are ordered in relation to acquiring loads and releasing stores on avg. To prevent false sharing I've padded the class since there may be tens to hundreds of instances of the accumulator and updates happen per consumed record.
The JMH benchmark I've added shows a slight uplift in average time per op for both reads and writes compared to the current implementation.
Results of task
:sdks:java:io:kafka:jmh:jmh
on a t2d-standard-60 Cloud Workstation:Note that this test likely does not highlight the effect of padding since it doesn't construct a large pool of accumulators.
Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:
addresses #123
), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, commentfixes #<ISSUE NUMBER>
instead.CHANGES.md
with noteworthy changes.See the Contributor Guide for more tips on how to make review process smoother.
To check the build health, please visit https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md
GitHub Actions Tests Status (on master branch)
See CI.md for more information about GitHub Actions CI or the workflows README to see a list of phrases to trigger workflows.