pub struct InstancePool { /* private fields */ }Expand description
Pre-instantiated instance pool. Backed by a per-tuple
crossbeam_channel of pre-spawned instances; see module docs for the
channel layout, reset trade-off, and streaming-spawn carve-out.
Implementations§
Source§impl InstancePool
impl InstancePool
Sourcepub fn new(cfg: InstancePoolConfig) -> Self
pub fn new(cfg: InstancePoolConfig) -> Self
Construct a new pool with the given config.
Sourcepub async fn acquire(
&self,
executor: &TensorWasmExecutor,
wasm: &[u8],
cfg: SpawnConfig,
) -> Result<PooledInstance, ExecError>
pub async fn acquire( &self, executor: &TensorWasmExecutor, wasm: &[u8], cfg: SpawnConfig, ) -> Result<PooledInstance, ExecError>
Acquire a pre-spawned instance or fall through to a fresh spawn.
Algorithm (T37):
- Compute the
(tenant, module_hash)key — building the entry on first observation by compiling the module (via the executor’s cached path), allocating a bounded channel of the configured size, and pre-spawningwarm_instances_per_tupledetached instances into it. try_recvon the per-tuple channel. On hit, register the drawn instance with the executor and return aPooledInstancehandle.- On miss, fall through to
TensorWasmExecutor::spawn_instanceso the call still proceeds (admission control still applies — the executor’smax_instancescap fires here if saturated).
Streaming spawns (SpawnConfig::streaming set) bypass the
warm-channel try_recv and always fall through to a fresh spawn:
the streaming context is one-shot (the gateway-held receiver is
drained per call), so the warm channel never holds streaming
instances.
Sourcepub async fn release(
&self,
executor: &TensorWasmExecutor,
pooled: PooledInstance,
cfg: &SpawnConfig,
)
pub async fn release( &self, executor: &TensorWasmExecutor, pooled: PooledInstance, cfg: &SpawnConfig, )
Release an instance back to the pool.
The instance is detached from the executor’s registry (the slot
stays charged for the moment) and dropped — its linear memory
could be holding sensitive guest state, so “reset” here means
“re-instantiate”, never “rewind”. A fresh replacement is then
spawned from the cached wasmtime::Module and try_send’d to
the channel; on full / send-error / streaming carve-out / reset
deadline exceeded, the replacement is dropped and the slot is
released.
pooled carries the originating module hash so the release path
dispatches to the correct per-tuple channel without re-hashing
(the release path no longer has the wasm bytes on hand).
Sourcepub fn warm_count(&self) -> usize
pub fn warm_count(&self) -> usize
Number of currently warm (in-channel) instances across all tuples.
Sourcepub fn draws_total(&self) -> usize
pub fn draws_total(&self) -> usize
Total successful pool draws (hits + misses). Monotonic counter.
Sourcepub fn hit_count(&self) -> usize
pub fn hit_count(&self) -> usize
Draws that hit a warm instance in the channel. Monotonic counter.
Sourcepub fn miss_count(&self) -> usize
pub fn miss_count(&self) -> usize
Draws that fell through to a fresh spawn. Monotonic counter.
Sourcepub fn drops_total(&self) -> usize
pub fn drops_total(&self) -> usize
Number of pool drops (channel full, reset failure, streaming carve-out, or reset deadline exceeded). Monotonic counter.
Sourcepub fn config(&self) -> &InstancePoolConfig
pub fn config(&self) -> &InstancePoolConfig
Borrow the pool’s configuration.
Sourcepub fn shutdown(&self, executor: &TensorWasmExecutor)
pub fn shutdown(&self, executor: &TensorWasmExecutor)
Drain every warm channel and release its instances. Called by embedders that want to free pool-held wasmtime resources without dropping the executor (e.g. on a config reload).
Idempotent — calling on an already-empty pool is a no-op. Slot accounting on the executor is restored: every instance pulled out is dropped, and the corresponding slot is released.
Auto Trait Implementations§
impl !RefUnwindSafe for InstancePool
impl !UnwindSafe for InstancePool
impl Freeze for InstancePool
impl Send for InstancePool
impl Sync for InstancePool
impl Unpin for InstancePool
impl UnsafeUnpin for InstancePool
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more