[FLINK-38825] Introduce AsyncBatchFunction and AsyncBatchWaitOperator #27355
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.
Motivation
Flink’s existing
AsyncFunctionprocesses records one-by-one, which is not optimal for high-latency inference workloads such as machine learning model serving, where batching requests can significantly improve throughput and resource utilization (e.g. GPU/remote inference services).Currently, users have to implement batching logic outside of Flink or embed complex buffering logic inside a single-record
AsyncFunction, which is error-prone and hard to evolve.This PR introduces a minimal, batch-oriented async abstraction as a foundation for future AI / inference-related extensions.
What is proposed in this PR
This PR adds a small, additive, and backward-compatible set of building blocks:
AsyncBatchFunction(PublicEvolving API)A new async function interface that allows processing a batch of input elements in a single async invocation.
AsyncBatchWaitOperator(runtime operator)A minimal unordered async batch operator that:
maxBatchSizeis reachedStream API entry point
A new
AsyncDataStream.unorderedWaitBatch(...)method to wire the operator in the DataStream API.Unit tests
Tests validating batch triggering, result emission, and exception propagation.
Scope and intentional limitations
This PR is intentionally minimal and does not include:
AsyncFunctionorAsyncWaitOperatorThese aspects are expected to be explored incrementally in follow-up PRs once the core abstraction is agreed upon.
Why this approach
Follow-up work (out of scope for this PR)
Potential next steps include:
Compatibility