Add micro-batching and async HTTP to Dataflow streaming pipeline#10
Merged
Conversation
The `with beam.Pipeline()` context manager calls wait_until_finish(), which blocks forever for streaming pipelines. Use explicit pipeline.run() with conditional wait gated on --no_wait. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or 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
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.
Summary
Replace the single-message synchronous HTTP pipeline with micro-batching and async HTTP to improve streaming inference throughput by ~20-200x. At high traffic, up to 50 messages are grouped into a single
/predictcall. At low traffic, partial batches flush after 1 second so no message waits indefinitely.Changes
Pipeline (
src/dataflow/iris_streaming_pipeline.py)CallFastAPIService(1 msg → 1 sync HTTP call) withBatchCallFastAPIService(up to 50 msgs → 1 async HTTP call)BatchElementswithmax_batch_duration_secs=1for stateful micro-batching across Beam bundles — avoids the problem where defaultBatchElementsis a no-op on Dataflow streaming at low volumeaiohttpwithTCPConnector(limit=4)for async HTTP, overlapping concurrent batch calls within a workerasyncioevent loop insetup()/teardown()lifecycle (standard pattern for async I/O in Beam DoFns)--batch_size(default 50) and--max_batch_duration_secs(default 1.0) CLI args for tuningrequestsandwindowimportsDeploy workflow (
.github/workflows/deploy-dataflow.yaml)--batch_size 50and--max_batch_duration_secs 1.0to the pipelineDocs
docs/scale_inference_batching.mdplan to reflect windowless approach withmax_batch_duration_secsReadme.mdstreaming architecture section with batching and async HTTP detailsTesting
python -m py_compile src/dataflow/iris_streaming_pipeline.py)python -m pytest test/)Deploy Dataflow Streamingworkflow withenvironment=stagingBatch prediction failed (N instances)pattern — N should be ~50 at load, 1-few at low traffic)