Skip to content

MultiBufferEntity add loop to produce content. - #1366

Merged
l-trotta merged 7 commits into
mainfrom
fix-1339-multibuffer-loop
Nov 5, 2026
Merged

l-trotta merged 7 commits into
mainfrom
fix-1339-multibuffer-loop

Conversation

@l-trotta

@l-trotta l-trotta commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Fixes #1339. MultiBufferEntity (rest5 and legacy) wrote only one buffer per output event, causing thousands of small writes per bulk request; it now keeps writing while the channel accepts data, and groups small buffers into a 16 KiB staging buffer to be sent once.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The test reuses an exhausted entity, so subsequent iterations never exercise failed() with unsent staged bytes; each iteration needs a fresh entity.

1 open issue
What changed in this PR

This PR addresses #1339 by reducing small writes in multi-buffer request bodies for both REST transports, targeting bulk-request I/O overhead.

Changes:

  • Loop through buffers while writes are fully accepted.
  • Coalesce small buffers into a reusable 16 KiB staging buffer while preserving partial-write state.
  • Add tests for coalescing, backpressure, completion, retries, and input-buffer preservation.
File Description
java-client/​src/​test/​java/​co/​elastic/​clients/​transport/​rest5_client/​MultiBufferEntityTest.java Adds REST5 channel and retry tests.
java-client/​src/​test/​java/​co/​elastic/​clients/​transport/​rest_client/​MultiBufferEntityTest.java Adds legacy encoder and retry tests.
java-client/​src/​main/​java/​co/​elastic/​clients/​transport/​rest5_client/​MultiBufferEntity.java Adds staged writes, looping, and pending-byte availability reporting.
java-client/​src/​main/​java/​co/​elastic/​clients/​transport/​rest_client/​MultiBufferEntity.java Adds staged writes and looping for the legacy transport.

Review effort: Balanced

@l-trotta
l-trotta merged commit be55286 into main Nov 5, 2026
9 of 13 checks passed
@l-trotta
l-trotta deleted the fix-1339-multibuffer-loop branch November 5, 2026 13:41
@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown

The backport to 8.19 failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-8.19 8.19
# Navigate to the new working tree
cd .worktrees/backport-8.19
# Create a new branch
git switch --create backport-1366-to-8.19
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick --mainline 1 be55286f456d1f3114d5aefd6ed435dda0f25d43
# Push it to GitHub
git push --set-upstream origin backport-1366-to-8.19
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-8.19

Then, create a pull request where the base branch is 8.19 and the compare/head branch is backport-1366-to-8.19.

@l-trotta

l-trotta commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

manually packporting to 8.19 only the relevant legacy rest client part.

l-trotta added a commit that referenced this pull request Nov 5, 2026
* keep feeding the encoder while it accepts bytes in multibuffer entity

* rest5 MultiBufferEntity: coalesce small buffers into a 16 KiB staging buffer

to fix bug for http2

* avoid buffering single body requests in staging buffer

* better explain rest5 mbe produce

* unit tests

* apply same staging buffer logic to legacy rest client

* rest5 MultiBufferEntityTest: use a fresh entity per retry attempt
l-trotta added a commit that referenced this pull request Nov 5, 2026
* keep feeding the encoder while it accepts bytes in multibuffer entity

* rest5 MultiBufferEntity: coalesce small buffers into a 16 KiB staging buffer

to fix bug for http2

* avoid buffering single body requests in staging buffer

* better explain rest5 mbe produce

* unit tests

* apply same staging buffer logic to legacy rest client

* rest5 MultiBufferEntityTest: use a fresh entity per retry attempt

Co-authored-by: Laura Trotta <153528055+l-trotta@users.noreply.github.com>
l-trotta added a commit that referenced this pull request Nov 5, 2026
* keep feeding the encoder while it accepts bytes in multibuffer entity

* rest5 MultiBufferEntity: coalesce small buffers into a 16 KiB staging buffer

to fix bug for http2

* avoid buffering single body requests in staging buffer

* better explain rest5 mbe produce

* unit tests

* apply same staging buffer logic to legacy rest client

* rest5 MultiBufferEntityTest: use a fresh entity per retry attempt

Co-authored-by: Laura Trotta <153528055+l-trotta@users.noreply.github.com>
l-trotta added a commit that referenced this pull request Nov 5, 2026
* keep feeding the encoder while it accepts bytes in multibuffer entity

* rest5 MultiBufferEntity: coalesce small buffers into a 16 KiB staging buffer

to fix bug for http2

* avoid buffering single body requests in staging buffer

* better explain rest5 mbe produce

* unit tests

* apply same staging buffer logic to legacy rest client

* rest5 MultiBufferEntityTest: use a fresh entity per retry attempt

Co-authored-by: Laura Trotta <153528055+l-trotta@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RestClientTransport sends bulk bodies as one HTTP chunk / TLS record / syscall per NDJSON buffer, burning ~45x the reactor CPU of the HLRC

2 participants