sandboxset: thread-safe sandbox pool (issue #217)#415
Closed
AmiBuch wants to merge 6 commits intoopen-lambda:mainfrom
Closed
sandboxset: thread-safe sandbox pool (issue #217)#415AmiBuch wants to merge 6 commits intoopen-lambda:mainfrom
sandboxset: thread-safe sandbox pool (issue #217)#415AmiBuch wants to merge 6 commits intoopen-lambda:mainfrom
Conversation
…ace and microservice like architecture
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.
sandboxset: Step 1 — thread-safe sandbox pool (issue #217)Problem
Each
LambdaInstanceruns a goroutine (~8 KB stack) that sits idle waiting on channels. Ten warm instances = 80+ KB wasted before serving a single request. The goroutine-per-instance model adds unnecessary complexity and memory overhead.What this PR does
Introduces
go/worker/sandboxsetas a new, self-contained package that provides a mutex-protected pool of sandboxes for a single Lambda function — no goroutines required.The pool itself costs ~500 bytes regardless of how many sandboxes it holds.
Sandbox lifecycle:
Design decisions
Get(create/reuse),Put(return),Destroy(kill),Close(cleanup) — four methods, nothing elseget.go,put.go,destroy.go,close.go— each method is independently readableapi.gois purely declarative — interface, config, and constructor only; 3 exported symbols totalUnpause()failure inGetalready handles this with destroy-and-retryGet— theinUseflag is set under the lock, thenUnpauseruns outside it so a slow container never stalls the whole poolDestroy— swap-with-tail, no shiftingConfig.ScratchDirs(*common.DirMaker) creates a unique scratch directory per sandbox internally, soGet()is zero-argsandboxsetimportssandbox(interfaces only);sandboxdoes not importsandboxsetPublic API
What this PR does NOT do
LambdaInstanceand its goroutines are unchanged — that is Step 2Warm/Shrink), metrics, or stats — those can be added in later PRsNext steps
LambdaFunc.instanceslist +LambdaInstancegoroutines with aSandboxSetSandboxSetas the node abstraction in the zygote tree, replacing individual containers