-
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
[BEAM-13015] Update the SDK harness grouping table to be memory bounded based upon the amount of assigned cache memory and to use an LRU eviction policy. #17327
Conversation
…n amount of assigned cache memory and also use an LRU policy for evicting entries from the table.
R: @youngoli |
Run Java PreCommit |
Run Python_PVR_Flink PreCommit |
Run Java PreCommit |
R: @Abacn |
@Abacn - could you please review this change? |
} | ||
return tableEntry; | ||
}); | ||
weight += entry.getWeight(); |
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.
is this accurate if entry is not new?
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.
Fixed and updated tests since it turned out we weren't accounting for the grouping table key.
@SuppressWarnings({ | ||
"nullness" // TODO(https://issues.apache.org/jira/browse/BEAM-10402) | ||
}) | ||
@NotThreadSafe |
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.
Document why? Also seems to contradict the requirement of Shrinkable?
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.
Documented that put
and flush
must be called from the bundle processing thread. shrink
can be called from any thread.
|
||
// Get the updated weight now that the cache may have been shrunk and respect it | ||
long currentMax = maxWeight.get(); | ||
if (weight > currentMax) { |
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.
If this is triggered by shrink() why not do it in shrink but instead rely on new input?
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.
Because we want to make sure that we only produce output from the bundle processing thread and not from an arbitrary thread that caused the shrinking to happen. Added a comment to reflect.
|
||
table.put("DDDD", 6, receiver); | ||
assertThat(receiver.outputElems, hasItem((Object) KV.of("DDDD", 6L))); | ||
// Insert three values which even with compaction isn't enough so we evict D & E to get |
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.
s/D & E/A & B/
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.
Done
@y1chi PTAL |
groupingKey, | ||
(key, tableEntry) -> { | ||
if (tableEntry == null) { | ||
weight += groupingKey.getWeight(); |
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.
remove this?
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 adds the weight of the key, and not the 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.
isn't entry.getWeight() = key.getWeight() + accumulator.getWeight()?
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.
There are two cases.
- key == structural key, then:
- GroupingTableKey weight = key weight + windows weight + pane info weight
- GroupingTableEntry weight = reference weight + accumulator weight
- key != structural key, then:
- GroupingTableKey weight = structural key weight + windows weight + pane info weight
- GroupingTableEntry weight = key weight + accumulator weight
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.
LGTM
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.
As far as I can tell it looks good, although I had some trouble following all the various weights involved so I'm glad Yichi's here to provide a second set of eyes.
Iterator<GroupingTableEntry> iterator = lruMap.values().iterator(); | ||
while (iterator.hasNext()) { | ||
GroupingTableEntry valueToFlush = iterator.next(); | ||
weight -= valueToFlush.getWeight() + valueToFlush.getGroupingKey().getWeight(); |
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.
I'm having some trouble following all the different weights, and my first instinct is that since valueToFlush contains the GroupingKey, that this would count the weight of the grouping key twice (and presumably this would be bad because it wasn't counted twice when being originally added to the max weight).
Run Java PreCommit |
I happened to do some benchmarking for a separate change (#17641) and noticed that this PR seems to reduce the performance significantly. Before (https://github.com/robertwb/incubator-beam/tree/java-combine-key-old) I was getting stats
(two benchmarks here: globally windowed and not) but after merging this change I'm seeing
|
I should note that before either change I was getting on the order of 15k ops/sec. |
Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:
R: @username
).[BEAM-XXX] Fixes bug in ApproximateQuantiles
, where you replaceBEAM-XXX
with the appropriate JIRA issue, if applicable. This will automatically link the pull request to the issue.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.