[Flink] Cache batch side input materialization in Flink 2 - #39867
Conversation
719d9ef to
0a46be6
Compare
0a46be6 to
a79f23d
Compare
|
Assigning reviewers: R: @Abacn for label website. Note: If you would like to opt out of this review, comment Available commands:
The PR bot will only process comments in the main thread (not review comments). |
Abacn
left a comment
There was a problem hiding this comment.
Thanks, a few questions
-
What is the consideration of exclude portable runner? It would be beneficial to have classic/portable runner feature in sync, as the latter one is the only one available for Python and Go SDKs
-
Similarly what is the consideration to disable streaming? Since this is an opt-in option, why hard code to make streaming ineffective
| void setFasterCopy(Boolean fasterCopy); | ||
|
|
||
| @Description( | ||
| "Batch/DataStream mode only (Flink 2.x): cache materialized side-input views per " |
There was a problem hiding this comment.
If it's Flink 2.x only, revert the changes on common runners/flink/src/
|
Thank you for the review!
Removed 👍
We have only thoroughly tested this with Java production workflows and would like to keep it tightly scoped. Portable side inputs also go through the Fn State API and SDK harness instead of SideInputReader, so this cache doesn't apply directly and seems like a bigger piece of work due to the different SDK harnesses.
Due to the nature of side inputs in unbounded streaming pipelines, the same window can be updated later. Since the cache is shared across the task manager, I'm worried some subtasks could use stale data for a bit. In batch processing side inputs should only be written once before they're read, so this works well. But I am open to removing it if you think opt-in is enough here. Wdyt? |
|
Please check the following
|
|
Hey @Abacn thanks for the thorough review, very helpful.
I went with this suggestion, ran a production test and it seems to be working as effectively as the previous version. Please let me know if it looks good or something is still not quite right 🤞 |
Summary
Automatically cache materialized side-input views for classic Java Flink DataStream execution when the side input is bounded, uses the default trigger, and has zero allowed lateness.
The cache is scoped by Flink job ID, task attempt,
PCollectionView, and window. It uses soft values, expires entries five minutes after access, and invalidates an entry after a side-input state update. A retried task rematerializes its values, while operator cleanup leaves shared entries available to peer subtasks and later operators.No pipeline option is required. Portable side-input delivery remains unchanged. Streaming pipelines only cache side inputs that satisfy the bounded, single-pane eligibility checks.
This restores the reuse provided by the removed Flink DataSet runner's broadcast-variable materialization. Beam's Spark runner and Spark structured-streaming runner also cache batch side-input materialization.
Fixes #39866.
Why
Moving production workloads from the Flink 1 DataSet runner to the Flink 2 DataStream runner caused large performance regressions when they repeatedly accessed materialized side inputs.
The DataStream runner currently reads the stored iterable and reapplies the
ViewFnfor every side-input access. For a map view, repeated access rebuilds the map for every main-input element.We observed this across multiple production workloads where map side inputs contained tens of thousands of rows and the main inputs contained billions of records. Caching changes repeated reconstruction into one materialization per job, task attempt, view, and window in each TaskManager JVM.
Performance
These anonymized production measurements used matching input partitions for each baseline and candidate.
Implementation
Scope
This PR changes the classic Java Flink 2 DataStream runner. Portable side-input delivery, GroupByKey translation, and pre-aggregation remain unchanged.
Streaming execution is not disabled as a mode. Only bounded side inputs with stable single-pane windowing are eligible for caching.
Validation
FlinkCachedSideInputReaderTestandFlinkPipelineOptionsTeston Flink 2.0 and 2.2Unit coverage includes eligibility checks, repeated reads, sharing between reader instances, job/view/window key separation, retry rematerialization, cached nulls, invalidation, uncached views, and exception propagation.
Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:
CHANGES.mdwith noteworthy changes.See the Contributor Guide for more tips on making the review process smoother.