perf(orchestrator): coalesce NBD header + max payload in one read - #3373
Open
AdaAibaby wants to merge 2 commits into
Open
perf(orchestrator): coalesce NBD header + max payload in one read#3373AdaAibaby wants to merge 2 commits into
AdaAibaby wants to merge 2 commits into
Conversation
Add nbdRequestHeaderSize = 28 constant and increase dispatchBufferSize from 4 MiB to 4 MiB + 28 bytes. An NBD request is [28-byte header][payload]. With a 4 MiB buffer a max-size 4 MiB payload arrives in two Read calls: the first fills the buffer with [28B header + (4MiB - 28B) payload], and a second call fetches the remaining 28 bytes. Adding 28 bytes to the buffer lets the entire [28B header + 4MiB payload] fit in a single Read, saving one syscall per max-size request. Memory impact: 28 bytes per sandbox connection — negligible. Also replace all bare 28 literals in Handle() with nbdRequestHeaderSize, and remove the now-resolved TODO comment. Fixes e2b-dev#3355
AdaAibaby
force-pushed
the
fix/nbd-dispatch-buffer-header-size
branch
from
July 25, 2026 07:57
41bb733 to
f729c65
Compare
ValentaTomas
force-pushed
the
main
branch
2 times, most recently
from
July 25, 2026 22:53
5aad415 to
d71980e
Compare
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.
fix #3355
Problem
dispatchBufferSizewas exactly 4 MiB — the maximum typical data payload size. Every NBD request also carries a 28-byte header, so a max-size (4 MiB) write required twoReadsyscalls instead of one:The code had a TODO acknowledging this:
Fix
nbdRequestHeaderSize = 28named constant — replaces all bare28literals in the dispatch loop, making the header-size relationship explicit.dispatchBufferSizeto4*1024*1024 + nbdRequestHeaderSize.With the new buffer size,
[28B header + 4MiB payload]fits in a singleReadcall, saving one syscall per max-size request. For I/O-heavy sandboxes doing large sequential block writes, this adds up across thousands of requests.Memory impact: 28 bytes per sandbox connection — negligible at any scale.
Tests
TestDispatchMaxSizeWrite— sends a 4 MiB write (header + full payload as one chunk) and verifies the payload reaches the backend with correct offset and full data integrity.nbdRequest()helper updated to usenbdRequestHeaderSizeinstead of a bare28./cc @jakubno @dobrac @ValentaTomas @arkamar @tvi Looking forward to your code review.