[Flink] Cache batch side input materialization in Flink 2 - #39867
[Flink] Cache batch side input materialization in Flink 2#39867pkuzmickas wants to merge 2 commits into
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
|
Summary
Cache materialized side-input views for classic Flink DataStream batch execution when
--cacheSideInputMaterialization=true.The option is disabled by default and bypassed in streaming mode. The cache is scoped by Flink job ID,
PCollectionView, and window; it uses soft values, expires entries five minutes after access, invalidates an entry after a side-input state update, and clears job entries during operator cleanup.This restores the reuse provided by the removed Flink DataSet runner's broadcast-variable materialization. Beam's Spark runner and Spark structured-streaming runner use cached side-input readers for batch execution.
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, view, and window in each TaskManager JVM.
Performance
These anonymized production measurements used the same input partition for each baseline and candidate.
Implementation
SideInputReaderonly when the new option is enabled.Scope
This PR intentionally excludes streaming execution, portable side-input delivery, GroupByKey translation, and pre-aggregation changes.
Validation
spotlessJavaCheckFlinkCachedSideInputReaderTeston Flink 2.0, 2.1, and 2.2FlinkPipelineOptionsTeston Flink 2.0, 2.1, and 2.2Unit coverage includes repeated reads, job/view/window key separation, cached nulls, invalidation, exception propagation, the disabled default, and the streaming guard.
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.