Skip to content
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

[flink-runner] Improve Datastream for batch performances #32440

Open
wants to merge 32 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
df1d56b
[Flink] Set return type of bounded sources
jto Jul 23, 2024
ed922af
[Flink] Use a lazy split enumerator for bounded sources
jto Jul 23, 2024
24ce8fa
[Flink] Default to maxParallelism = parallelism in batch
jto Aug 19, 2024
b12c87b
[Flink] Avoid re-serializing trigger on every element
jto Aug 20, 2024
c8c3f96
[Flink] Avoid re-evaluating options every time a new state is stored
jto Aug 20, 2024
f002d49
[Flink] Only serialize states namespace keys if necessary
jto Aug 21, 2024
dd734b3
[Flink] Make ToKeyedWorkItem part of the DoFnOperator
jto Aug 6, 2024
89687e9
[Flink] Remove ToBinaryKV
jto Aug 19, 2024
b2727c8
[Flink] Refactor CombinePerKeyTranslator
jto Aug 8, 2024
feaa32e
[Flink] Combine before Reduce (no side-input only)
jto Aug 9, 2024
0c5237f
[Flink] Combine before GBK
jto Aug 23, 2024
6749b9e
[Flink] Combine before reduce (with side input)
jto Aug 28, 2024
85e58ac
[Flink] Force slot sharing group in batch mode
jto Aug 27, 2024
ec10076
[Flink] Disable bundling in batch mode
jto Aug 26, 2024
275b4d8
[Flink] Lower default max bundle size in batch mode
jto Aug 23, 2024
d3c4483
[Flink] Code cleanup
jto Aug 28, 2024
352ea78
[Flink] fix WindowDoFnOperatorTest
jto Aug 29, 2024
4532df1
[Flink] spotless
jto Aug 30, 2024
73378a2
[Flink] fix broken tests
jto Sep 10, 2024
615ec19
[Flink] Remove 1.14 compat code
jto Sep 12, 2024
fae1902
[Flink] Fix flaky test
jto Sep 12, 2024
d81369e
[Flink] Use a custom key type to better distribute load
jto Oct 16, 2024
8fb69f1
[Flink] Add post commit triggers
jto Oct 16, 2024
6c98da6
[Flink] licence
jto Oct 16, 2024
8169038
[Flink] spotless
jto Oct 16, 2024
687113a
Additional Flink github action trigger files
kennknowles Oct 18, 2024
80a7e22
[Flink] fix GBK streaming with side input
jto Nov 6, 2024
ac2eddc
[Flink] fix error management in lazy source
jto Nov 12, 2024
2c01ac0
[Flink] disable operator chaining in validatesRunner
jto Nov 13, 2024
e359eda
[Flink] fix lazy source enumerator behaviour on error
jto Nov 13, 2024
777dcf7
[Flink] set validates runner parallelism to 1
jto Nov 14, 2024
6161f4e
[Flink] add org.apache.beam.sdk.transforms.ParDoTest to sickbay
jto Nov 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/trigger_files/beam_PostCommit_Go_VR_Flink.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"comment": "Modify this file in a trivial way to cause this test suite to run",
"modification": 1,
"https://github.com/apache/beam/pull/32440": "testing datastream optimizations",
"https://github.com/apache/beam/pull/32648": "testing addition of Flink 1.19 support"
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"https://github.com/apache/beam/pull/32648": "testing flink 1.19 support"
"https://github.com/apache/beam/pull/32440": "testing datastream optimizations",
"https://github.com/apache/beam/pull/32648": "testing flink 1.19 support"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"comment": "Modify this file in a trivial way to cause this test suite to run",
"https://github.com/apache/beam/pull/32440": "test new datastream runner for batch"
"modification": 2
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"comment": "Modify this file in a trivial way to cause this test suite to run",
"modification": "1"
"https://github.com/apache/beam/pull/31156": "noting that PR #31156 should run this test",
"https://github.com/apache/beam/pull/32440": "test new datastream runner for batch"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"comment": "Modify this file in a trivial way to cause this test suite to run",
"modification": 1
"modification": 1,
"https://github.com/apache/beam/pull/32440": "test new datastream runner for batch"
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"comment": "Modify this file in a trivial way to cause this test suite to run",
"https://github.com/apache/beam/pull/31156": "noting that PR #31156 should run this test",
"https://github.com/apache/beam/pull/32440": "testing datastream optimizations",
"https://github.com/apache/beam/pull/32648": "testing addition of Flink 1.19 support"
}
3 changes: 2 additions & 1 deletion .github/trigger_files/beam_PostCommit_Python.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"comment": "Modify this file in a trivial way to cause this test suite to run.",
"modification": 3
"modification": 4,
"https://github.com/apache/beam/pull/32440": "test new datastream runner for batch"
}

3 changes: 2 additions & 1 deletion .github/trigger_files/beam_PostCommit_XVR_Flink.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"https://github.com/apache/beam/pull/32648": "testing Flink 1.19 support"
"https://github.com/apache/beam/pull/32440": "testing datastream optimizations",
"https://github.com/apache/beam/pull/32648": "testing addition of Flink 1.19 support"
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.beam.runners.core;

import java.util.Collection;
import org.apache.beam.model.pipeline.v1.RunnerApi;
import org.apache.beam.runners.core.triggers.ExecutableTriggerStateMachine;
import org.apache.beam.runners.core.triggers.TriggerStateMachines;
import org.apache.beam.sdk.transforms.DoFn;
Expand All @@ -41,6 +42,7 @@ public class GroupAlsoByWindowViaWindowSetNewDoFn<
extends DoFn<RinT, KV<K, OutputT>> {

private static final long serialVersionUID = 1L;
private final RunnerApi.Trigger triggerProto;

public static <K, InputT, OutputT, W extends BoundedWindow>
DoFn<KeyedWorkItem<K, InputT>, KV<K, OutputT>> create(
Expand Down Expand Up @@ -86,6 +88,7 @@ public GroupAlsoByWindowViaWindowSetNewDoFn(
this.windowingStrategy = noWildcard;
this.reduceFn = reduceFn;
this.stateInternalsFactory = stateInternalsFactory;
this.triggerProto = TriggerTranslation.toProto(windowingStrategy.getTrigger());
}

private OutputWindowedValue<KV<K, OutputT>> outputWindowedValue() {
Expand Down Expand Up @@ -124,8 +127,7 @@ public void processElement(ProcessContext c) throws Exception {
key,
windowingStrategy,
ExecutableTriggerStateMachine.create(
TriggerStateMachines.stateMachineForTrigger(
TriggerTranslation.toProto(windowingStrategy.getTrigger()))),
TriggerStateMachines.stateMachineForTrigger(triggerProto)),
stateInternals,
timerInternals,
outputWindowedValue(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,21 @@ public class CoderTypeSerializer<T> extends TypeSerializer<T> {

private final Coder<T> coder;

/**
* {@link SerializablePipelineOptions} deserialization will cause {@link
* org.apache.beam.sdk.io.FileSystems} registration needed for {@link
* org.apache.beam.sdk.transforms.Reshuffle} translation.
*/
private final SerializablePipelineOptions pipelineOptions;

private final boolean fasterCopy;

public CoderTypeSerializer(Coder<T> coder, SerializablePipelineOptions pipelineOptions) {
this(
coder,
Preconditions.checkNotNull(pipelineOptions)
.get()
.as(FlinkPipelineOptions.class)
.getFasterCopy());
}

public CoderTypeSerializer(Coder<T> coder, boolean fasterCopy) {
Preconditions.checkNotNull(coder);
Preconditions.checkNotNull(pipelineOptions);
this.coder = coder;
this.pipelineOptions = pipelineOptions;

FlinkPipelineOptions options = pipelineOptions.get().as(FlinkPipelineOptions.class);
this.fasterCopy = options.getFasterCopy();
this.fasterCopy = fasterCopy;
}

@Override
Expand All @@ -73,7 +71,7 @@ public boolean isImmutableType() {

@Override
public CoderTypeSerializer<T> duplicate() {
return new CoderTypeSerializer<>(coder, pipelineOptions);
return new CoderTypeSerializer<>(coder, fasterCopy);
}

@Override
Expand Down
8 changes: 7 additions & 1 deletion runners/flink/flink_runner.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,10 @@ class ValidatesRunnerConfig {
def sickbayTests = [
// TODO(https://github.com/apache/beam/issues/21306)
'org.apache.beam.sdk.transforms.ParDoTest$TimestampTests.testOnWindowTimestampSkew',
// Flink errors are not deterministic. Exception may just be
// org.apache.flink.runtime.operators.coordination.TaskNotRunningException: Task is not running, but in state FAILED
// instead of the actual cause. Real cause is visible in the logs.
'org.apache.beam.sdk.transforms.ParDoTest$LifecycleTests'
]

def createValidatesRunnerTask(Map m) {
Expand All @@ -249,7 +253,7 @@ def createValidatesRunnerTask(Map m) {
def pipelineOptionsArray = ["--runner=TestFlinkRunner",
"--streaming=${config.streaming}",
"--useDataStreamForBatch=${config.useDataStreamForBatch}",
"--parallelism=2",
"--parallelism=1",
]
if (config.checkpointing) {
pipelineOptionsArray.addAll([
Expand All @@ -266,6 +270,8 @@ def createValidatesRunnerTask(Map m) {
)
// maxParallelForks decreased from 4 in order to avoid OOM errors
maxParallelForks 2
def flinkConfDir = System.getProperty("user.dir") + "/runners/flink/src/test/validatesRunnerConfig"
environment("FLINK_CONF_DIR", flinkConfDir)
useJUnit {
if (config.checkpointing) {
includeCategories 'org.apache.beam.sdk.testing.UsesBundleFinalizer'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,16 @@ public static StreamExecutionEnvironment createStreamExecutionEnvironment(
flinkStreamEnv.setParallelism(parallelism);
if (options.getMaxParallelism() > 0) {
flinkStreamEnv.setMaxParallelism(options.getMaxParallelism());
} else if (!options.isStreaming()) {
// In Flink maxParallelism defines the number of keyGroups.
// (see
// https://github.com/apache/flink/blob/e9dd4683f758b463d0b5ee18e49cecef6a70c5cf/flink-runtime/src/main/java/org/apache/flink/runtime/state/KeyGroupRangeAssignment.java#L76)
// The default value (parallelism * 1.5)
// (see
// https://github.com/apache/flink/blob/e9dd4683f758b463d0b5ee18e49cecef6a70c5cf/flink-runtime/src/main/java/org/apache/flink/runtime/state/KeyGroupRangeAssignment.java#L137-L147)
// create a lot of skew so we force maxParallelism = parallelism in Batch mode.
LOG.info("Setting maxParallelism to {}", parallelism);
flinkStreamEnv.setMaxParallelism(parallelism);
}
// set parallelism in the options (required by some execution code)
options.setParallelism(parallelism);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public Long create(PipelineOptions options) {
if (options.as(StreamingOptions.class).isStreaming()) {
return 1000L;
} else {
return 1000000L;
return 5000L;
}
}
}
Expand Down Expand Up @@ -382,6 +382,13 @@ public Long create(PipelineOptions options) {

void setEnableStableInputDrain(Boolean enableStableInputDrain);

@Description(
"Set a slot sharing group for all bounded sources. This is required when using Datastream to have the same scheduling behaviour as the Dataset API.")
@Default.Boolean(true)
Boolean getForceSlotSharingGroup();

void setForceSlotSharingGroup(Boolean enableStableInputDrain);

static FlinkPipelineOptions defaults() {
return PipelineOptionsFactory.as(FlinkPipelineOptions.class);
}
Expand Down
Loading
Loading