feat: add batch consume to the source Hopper and adapters#135
Merged
Conversation
Add a BatchHandler (func(ctx, []Message) []Result) and a WithBatch(size, maxWait) Hopper option, driven by RunBatch/ReceiveBatch. The engine accumulates up to size messages per ordered lane, or until maxWait elapses on an injected clock, invokes the BatchHandler once, then settles each message by its positionally-aligned Result. Per-key ordering and the MaxInFlight bound are preserved, a result-count mismatch terminates the unmatched messages as poison (ErrBatchResultCount), and a decode failure is isolated to its own message. When a subscription advertises the Batched capability the engine hands it whole fetched batches and regroups them by key, falling back to per-message accumulation otherwise. Kafka exposes its polled records and JetStream its pull fetch through Batched; batch is opt-in, per-message stays the default. Covered by table-driven memsource tests (size/maxWait/drain triggers, per-message result mapping, ordering, capability path), an Example, and a fuzz test asserting batch + per-key ordering never loses, dups, or reorders within a key. Documents a Batch consume section in the concurrency guide. Signed-off-by: Joshua Temple <joshua.temple@stablekernel.com>
Signed-off-by: Joshua Temple <joshua.temple@stablekernel.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.
What this change does
Adds batch consume to the
sourceHopperand adapters (one of the four roadmap items from #131). ABatchHandler(func(ctx, []Message) []Result) plus aWithBatch(size, maxWait)option lets a consumer process many messages per call instead of one.The engine accumulates up to
sizemessages per ordered lane, or untilmaxWaitelapses on an injected clock, invokes theBatchHandleronce, then settles each message by its positionally-alignedResult. Per-key ordering and theMaxInFlightbound are preserved; a result-count mismatch terms the unmatched messages as poison (ErrBatchResultCount), and a decode failure is isolated to its own message.When a subscription advertises the
Batchedcapability the engine hands it whole fetched batches and regroups by key; otherwise it falls back to per-message accumulation. Kafka exposes its polled records and JetStream its pull fetch throughBatched. Batch is opt-in — per-message stays the default.Why
Sinks, stores, and downstream APIs are often far more efficient per call when fed in batches, but doing that by hand breaks per-key ordering and the in-flight bound. Folding batching into the
Hopperkeeps those invariants intact while letting throughput-sensitive consumers opt in with one option.Relates to: follows up the source Tier-1 PR (#131).
Checklist
git commit -s) per the DCOtype: subject)mage checkruns in CI across the workspace and the GOWORK=off source destinations