Repository navigation
Conversation
Sandboxes of one build already share a single source memfile on the host,
but UFFDIO_COPY faults a private physical copy of those identical read-only
base pages into each sandbox. Collapsing N copies to one (pmem+DAX shared
read-only base) needs the siblings on the same node first, and placement
spreads them today.
Bias best-of-K toward nodes already running same-build sandboxes:
- Thread build_id through SandboxResources into the score.
- Multiplicative discount (1 - weight*min(sameBuild,cap)/cap) on the load
score, so affinity only reorders candidates that already pass admission
and never outweighs real load. Capped so it cannot pull an unbounded pile
onto one node.
- Off by default (weight 0): zero behaviour change until an operator opts in
via best-of-k-template-affinity-weight / -cap.
Observability (recorded whether or not the weight is on, so the baseline is
visible before sharing is built and the lift after it is dialed up):
- api.orchestrator.template_affinity_placements{effect=colocated|spread}
- api.orchestrator.template_affinity_siblings histogram: in-flight same-build
siblings on the chosen node, i.e. the base copies a shared base could
collapse there.
- Structured debug log per same-build placement.
Tests: discount math and SameBuildInProgress (table), metric recording via a
ManualReader through the real placeSandbox path, and a seeded multi-template
fleet simulation through the real chooseNode showing the weight tightens
colocation (nodes-per-build 6.9 -> 5.6, colocation ~22% -> ~36% at weight
0.6, 24-seed mean).
Refs e2b-dev#3824, e2b-dev#3825.
AdaAibaby
requested review from
ValentaTomas,
dobrac and
jakubno
as code owners
November 20, 2026 08:44
This branch has not been deployed
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.
Why
Sandboxes of one build already share a single source memfile on the host, but UFFDIO_COPY faults a private physical copy of those identical read-only base pages into each sandbox. Collapsing N copies to one (a shared read-only base, pmem+DAX) is only possible if the siblings sit on the same node — and placement spreads them today. This biases placement so they land together, and measures how dense same-template colocation actually is, which is the go/no-go data for building the sharing.
What
build_idthroughSandboxResourcesinto the best-of-K score.(1 - weight*min(sameBuild,cap)/cap)on the load score: affinity only reorders candidates that already pass admission and never outweighs real load; capped so it cannot pull an unbounded pile onto one node.best-of-k-template-affinity-weight/-cap.Observability (recorded even when the weight is 0)
api.orchestrator.template_affinity_placements{effect=colocated|spread}api.orchestrator.template_affinity_siblingshistogram — in-flight same-build siblings on the chosen node, i.e. the base copies a shared base could collapse there.Tests
SameBuildInProgress(table-driven).ManualReaderover the realplaceSandboxpath (effect classification, siblings count, build-less creates skipped).chooseNode: weight 0.6 tightens nodes-per-build 6.9 -> 5.6 and raises colocation ~22% -> ~36% (24-seed mean). Deliberately asserts direction, not strict point-wise monotonicity (the discount interacts with best-of-K sampling).Safety / scope
api-only; serve/fault path untouched;orchestrator/envdunchanged. Zero added cardinality and zero behaviour change until the weight is raised./cc @ryan-sana Looking forward to your code review.