pub struct WarmPool<P: VmProvider + VmQuery + 'static> { /* private fields */ }Expand description
Warm pool of pre-restored microVMs.
Construct with WarmPool::start; register snapshots to keep warm with
WarmPool::register; check out entries with WarmPool::acquire.
The pool is Send + Sync; clone the inner Arc if you need to pass it
across thread boundaries.
Implementations§
Source§impl<P: VmProvider + VmQuery + Clone + 'static> WarmPool<P>
impl<P: VmProvider + VmQuery + Clone + 'static> WarmPool<P>
Sourcepub fn start(
provider: P,
config: WarmPoolConfig,
validator: Arc<dyn EntryValidator>,
) -> Self
pub fn start( provider: P, config: WarmPoolConfig, validator: Arc<dyn EntryValidator>, ) -> Self
Start a pool with a fresh refill thread.
The pool holds a clone of provider; another clone runs inside the
refill thread. Providers from microvm-runtime are cheap to clone
(Arc-backed).
Sourcepub fn register(&self, stack: StackKey, source_snapshot: SnapshotRef)
pub fn register(&self, stack: StackKey, source_snapshot: SnapshotRef)
Tell the pool which snapshot to keep warm for stack. The refill
thread will bring this bucket up to min_depth on its next tick.
Calling register again for the same key replaces the snapshot but
keeps existing entries — they continue to be served until evicted by
age or validation. Operators wanting hard-cutover should pair this
with unregister.
Sourcepub fn unregister(&self, stack: &StackKey)
pub fn unregister(&self, stack: &StackKey)
Stop tracking stack. Existing entries are destroyed immediately
(best-effort) so the pool doesn’t keep paying for them.
Sourcepub fn acquire(&self, stack: &StackKey) -> Option<WarmPoolHandle>
pub fn acquire(&self, stack: &StackKey) -> Option<WarmPoolHandle>
Hand off a pre-restored VM. Pops an entry from stack’s bucket and
validates it; on Healthy, returns a WarmPoolHandle. On
Unhealthy, the entry is destroyed (validation_failures counter
increments) and the next entry is tried. Returns None if the bucket
is empty or every remaining entry failed validation.
The returned WarmPoolHandle::source_snapshot is what the caller
passes back to VmProvider::create_vm_with_spec after applying its
own SnapshotRef::network_overrides.
Sourcepub fn metrics(&self) -> WarmPoolMetrics
pub fn metrics(&self) -> WarmPoolMetrics
Snapshot of counters for observability scraping.