Documentation
¶
Overview ¶
Package wasm is the in-memory warm-worker pool for WASM sandboxes (Phase 5). Unlike internal/pool/vmm, slots are not persisted — worker processes do not survive a daemon restart.
Index ¶
- Variables
- func NewSlotID() string
- func RunRefill(ctx context.Context, pool *Pool, cfg RefillConfig, spawner Spawner, ...)
- type Metrics
- type Pool
- func (p *Pool) Acquire(_ context.Context, digest, modulePath string, memoryMB int) (*Slot, error)
- func (p *Pool) Close() (drained int)
- func (p *Pool) DepthFor(digest string) int
- func (p *Pool) DropModule(digest string)
- func (p *Pool) ListTargets() []struct{ ... }
- func (p *Pool) MarkSpawning(digest string)
- func (p *Pool) Metrics() *Metrics
- func (p *Pool) NoteModule(digest, modulePath string)
- func (p *Pool) ReadyCount(digest string) int
- func (p *Pool) RecordLoaded(slot *Slot)
- func (p *Pool) Run(ctx context.Context, cfg RefillConfig, spawner Spawner)
- func (p *Pool) SetDefaultDepth(n int)
- func (p *Pool) SetDefaultMemoryMB(n int)
- func (p *Pool) SetSpawner(s Spawner)
- func (p *Pool) SlotDir(digest, slotID string) string
- func (p *Pool) SpawnBudget(digest string) int
- func (p *Pool) UnmarkSpawning(digest string)
- func (p *Pool) WarmOne(ctx context.Context, digest, modulePath string) (*Slot, error)
- type RefillConfig
- type Slot
- type Snapshot
- type Spawner
- type SupervisorSpawner
Constants ¶
This section is empty.
Variables ¶
var ErrNoSlot = errors.New("wasm warm pool: no slot available")
ErrNoSlot means the warm pool has no ready worker for the requested module digest.
Functions ¶
Types ¶
type Metrics ¶
type Metrics struct {
Hits atomic.Int64
Misses atomic.Int64
Refilled atomic.Int64
SpawnFail atomic.Int64
}
Metrics tracks warm-pool hit/miss and refill counters (expvar-friendly via Snapshot).
func (*Metrics) RecordRefill ¶
func (m *Metrics) RecordRefill()
func (*Metrics) RecordSpawnFail ¶
func (m *Metrics) RecordSpawnFail()
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool keeps pre-loaded workers keyed by module digest.
func New ¶
New constructs a warm pool. runDir is the WASM runtime root (pool slots live under runDir/pool/).
func (*Pool) Acquire ¶
Acquire removes one warm slot for digest whose MemoryMB matches. Returns ErrNoSlot on miss.
func (*Pool) DropModule ¶
DropModule evicts warm slots and refill targets for digest after module GC.
func (*Pool) ListTargets ¶
ListTargets returns digest/path pairs eligible for refill.
func (*Pool) MarkSpawning ¶
MarkSpawning increments the in-flight spawn counter for digest.
func (*Pool) NoteModule ¶
NoteModule registers a digest/path pair for background refill.
func (*Pool) ReadyCount ¶
ReadyCount returns how many warm slots are queued for digest.
func (*Pool) RecordLoaded ¶
RecordLoaded pushes a freshly warmed slot into the ready queue.
func (*Pool) Run ¶
func (p *Pool) Run(ctx context.Context, cfg RefillConfig, spawner Spawner)
Run starts the refill loop until ctx is cancelled. No-op when pool or spawner is nil.
func (*Pool) SetDefaultDepth ¶
SetDefaultDepth sets the target warm depth per module digest when depth is unset.
func (*Pool) SetDefaultMemoryMB ¶
SetDefaultMemoryMB sets the guest memory cap used when warming pool slots.
func (*Pool) SetSpawner ¶
SetSpawner injects the worker spawner (production: SupervisorSpawner).
func (*Pool) SpawnBudget ¶
SpawnBudget returns how many slots refill should create for digest on this tick.
func (*Pool) UnmarkSpawning ¶
UnmarkSpawning decrements the in-flight spawn counter after a failed warm.
type RefillConfig ¶
RefillConfig holds timing knobs for the background refill loop.
type Slot ¶
type Slot struct {
ID string
ModuleDigest string
ModulePath string
SocketPath string
WorkerKey string
MemoryMB int
LoadedAt time.Time
}
Slot is one warm worker with its module already compiled inside the worker.
type Spawner ¶
type Spawner interface {
Warm(ctx context.Context, slotID, socketPath, modulePath string, memoryMB int) error
Shutdown(slotID string) error
}
Spawner warms a worker subprocess with a module already compiled (LoadModule done).
type SupervisorSpawner ¶
type SupervisorSpawner struct {
Supervisor *worker.Supervisor
PingWait time.Duration
MemoryMB int
}
SupervisorSpawner uses the shared worker.Supervisor to own pool slot processes.
func NewSupervisorSpawner ¶
func NewSupervisorSpawner(sup *worker.Supervisor) *SupervisorSpawner
NewSupervisorSpawner constructs a spawner backed by worker.Supervisor.
func (*SupervisorSpawner) Shutdown ¶
func (s *SupervisorSpawner) Shutdown(slotID string) error
Shutdown stops the worker subprocess for slotID.