-
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
Optimize Datastream for batch #31950
Closed
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jto
force-pushed
the
julient/patched-2.56
branch
from
July 24, 2024 09:43
568e44c
to
9641b2a
Compare
jto
changed the title
Reduce the maximum size of input splits in Flink to better distribute work in Datastream API
Optimize Datastream API for batch
Jul 26, 2024
This reverts commit 44d1271.
This reverts commit e885cb2.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR contains several optimizations for the Datastream API when used in Batch mode. In it's current state, using Datastream for batch is much slower than Dataset, this is an attempt to get it to the same performance level.
The following optimizations are implemented:
Same optimisation as #28045 for Datastream.
It has the same benefits with Datastream as with Dataset (up to 20% speedup).
I discovered the patch was also necessary for Datastream while migrating existing workflows from dataset to datastream by passing
--useDataStreamForBatch
.Use a lazy enumerator for bounded IOs reads
The existing enumerator eagerly distributes splits to workers. When splits are not all equal in size, the distribution causes a lot of skew. The new implementation is mimicking the behaviours of Flink's
StaticFileSplitEnumerator
where splits are lazily distributed to workers as they are consumed which results in better load balancing.Set the serializer on Bounded reads.
For some reason serializer was not set on Bounded reads.
TODO
Fix BQ IO issue
BQ writes do not behave the same with Datastream and garbage collection is much much slower. In dataset the IO will create 1 temp file per worker, this is not true with Datastream where it creates a lot (20x) more files.
Fix double encoding of window in GBK and CombinePerKey
Before shuffle
KV
are converted toKeyedWorkItem
, however the actual stream type is:DataStream<WindowedValue<KeyedWorkItem<K, byte[]>>>
Both
KeyedWorkItem
andWindowedValue
serialize the window. Since the conversion happens beforekeyBy
(shuffle), the duplication directly results in network overhead.I tried the simplest fix: move conversion after
keyBy
butWindowDoFnOperator
needs the stream it transforms be keyed so turningToBinaryKeyedWorkItem -> keyBy -> transform(doFnOperator)
intokeyBy -> ToBinaryKeyedWorkItem -> transform(doFnOperator)
is not possible.I also tried a similar fix using
reinterpretAsKeyedStream
to avoid this problem. The chain becomes:ToBinaryKV -> keyBy -> ToKeyedWorkItem -> reinterpretAsKeyedStream -> transform(doFnOperator)
butreinterpretAsKeyedStream
breaks operator chaining betweenToBinaryKeyedWorkItem
and the following operator which degrades performances even more.The best fix would be to not need
KeyedWorkItem
but that'd be a large change in Beam.Missing pre-shuffle combine on redure operator
The Dataset translation will translate
reduce
into apartial reduce -> shuffle -> reduce
. The Datastream translator is missing this optimization which make reduce operations much slower.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.