Refactor configuration for the pooling allocator (#5205)
This commit changes the APIs in the `wasmtime` crate for configuring the pooling allocator. I plan on adding a few more configuration options in the near future and the current structure was feeling unwieldy for adding these new abstractions. The previous `struct`-based API has been replaced with a builder-style API in a similar shape as to `Config`. This is done to help make it easier to add more configuration options in the future through adding more methods as opposed to adding more field which could break prior initializations.
This commit is contained in:
@@ -1,19 +1,13 @@
|
||||
use super::PoolingAllocationConfig;
|
||||
use arbitrary::Arbitrary;
|
||||
|
||||
use super::InstanceLimits;
|
||||
|
||||
/// Configuration for `wasmtime::InstanceAllocationStrategy`.
|
||||
#[derive(Arbitrary, Clone, Debug, Eq, PartialEq, Hash)]
|
||||
pub enum InstanceAllocationStrategy {
|
||||
/// Use the on-demand instance allocation strategy.
|
||||
OnDemand,
|
||||
/// Use the pooling instance allocation strategy.
|
||||
Pooling {
|
||||
/// The pooling strategy to use.
|
||||
strategy: PoolingAllocationStrategy,
|
||||
/// The instance limits.
|
||||
instance_limits: InstanceLimits,
|
||||
},
|
||||
Pooling(PoolingAllocationConfig),
|
||||
}
|
||||
|
||||
impl InstanceAllocationStrategy {
|
||||
@@ -21,37 +15,8 @@ impl InstanceAllocationStrategy {
|
||||
pub fn to_wasmtime(&self) -> wasmtime::InstanceAllocationStrategy {
|
||||
match self {
|
||||
InstanceAllocationStrategy::OnDemand => wasmtime::InstanceAllocationStrategy::OnDemand,
|
||||
InstanceAllocationStrategy::Pooling {
|
||||
strategy,
|
||||
instance_limits,
|
||||
} => wasmtime::InstanceAllocationStrategy::Pooling {
|
||||
strategy: strategy.to_wasmtime(),
|
||||
instance_limits: instance_limits.to_wasmtime(),
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Configuration for `wasmtime::PoolingAllocationStrategy`.
|
||||
#[derive(Arbitrary, Clone, Debug, PartialEq, Eq, Hash)]
|
||||
pub enum PoolingAllocationStrategy {
|
||||
/// Use next available instance slot.
|
||||
NextAvailable,
|
||||
/// Use random instance slot.
|
||||
Random,
|
||||
/// Use an affinity-based strategy.
|
||||
ReuseAffinity,
|
||||
}
|
||||
|
||||
impl PoolingAllocationStrategy {
|
||||
fn to_wasmtime(&self) -> wasmtime::PoolingAllocationStrategy {
|
||||
match self {
|
||||
PoolingAllocationStrategy::NextAvailable => {
|
||||
wasmtime::PoolingAllocationStrategy::NextAvailable
|
||||
}
|
||||
PoolingAllocationStrategy::Random => wasmtime::PoolingAllocationStrategy::Random,
|
||||
PoolingAllocationStrategy::ReuseAffinity => {
|
||||
wasmtime::PoolingAllocationStrategy::ReuseAffinity
|
||||
InstanceAllocationStrategy::Pooling(pooling) => {
|
||||
wasmtime::InstanceAllocationStrategy::Pooling(pooling.to_wasmtime())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user