Skip to content

Commit

Permalink
Make allocation strategy for wasmtime configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
aumetra committed Jun 6, 2024
1 parent 9cf1e09 commit 8a746e4
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
10 changes: 10 additions & 0 deletions crates/kitsune-config/src/mrf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ use serde::{Deserialize, Serialize};
use smol_str::SmolStr;
use std::{collections::HashMap, num::NonZeroUsize};

#[derive(Clone, Debug, Default, Deserialize, Serialize)]

Check warning on line 5 in crates/kitsune-config/src/mrf.rs

View check run for this annotation

Codecov / codecov/patch

crates/kitsune-config/src/mrf.rs#L5

Added line #L5 was not covered by tests
#[serde(rename_all = "kebab-case")]
pub enum AllocationStrategy {
OnDemand,
#[default]
Pooling,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct ArtifactCache {
pub path: SmolStr,
Expand Down Expand Up @@ -30,6 +38,8 @@ pub enum KvStorage {
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "kebab-case")]
pub struct Configuration {
#[serde(default)]
pub allocation_strategy: AllocationStrategy,
pub artifact_cache: Option<ArtifactCache>,
pub module_dir: SmolStr,
pub module_config: HashMap<SmolStr, SmolStr>,
Expand Down
9 changes: 7 additions & 2 deletions crates/kitsune-wasm-mrf/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use color_eyre::{eyre, Section};
use fred::{clients::RedisPool, interfaces::ClientLike, types::RedisConfig};
use futures_util::{stream::FuturesUnordered, Stream, TryFutureExt, TryStreamExt};
use kitsune_config::mrf::{
Configuration as MrfConfiguration, FsKvStorage, KvStorage, RedisKvStorage,
AllocationStrategy, Configuration as MrfConfiguration, FsKvStorage, KvStorage, RedisKvStorage,
};
use kitsune_derive::kitsune_service;
use kitsune_error::Error;
Expand Down Expand Up @@ -171,9 +171,14 @@ impl MrfService {
}
};

let allocation_strategy = match config.allocation_strategy {
AllocationStrategy::OnDemand => InstanceAllocationStrategy::OnDemand,
AllocationStrategy::Pooling => InstanceAllocationStrategy::pooling(),
};

let mut engine_config = Config::new();
engine_config
.allocation_strategy(InstanceAllocationStrategy::pooling())
.allocation_strategy(allocation_strategy)
.async_support(true)
.wasm_component_model(true);

Expand Down
15 changes: 14 additions & 1 deletion docs/src/configuring/mrf.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@ For example, you can use it to:

## Configuration

### `allocation-strategy`

⚠ You usually don't need to touch this setting!

It has two possible values:

- `on-demand`
- `pooling`

By default it is set to `pooling` which will offer the best throughput since Kitsune instantiates short-lived WASM modules, where pooled allocation can improve performance.

If Kitsune crashes on startup complaining about `failed to create stack pool mapping`, you might want to try changing this setting to `on-demand`.

### `module-dir`

This configuration option tells Kitsune where to scan for WASM modules to load and compile.
Expand All @@ -40,7 +53,7 @@ path = "./artifact-cache"
### `storage`

Kitsune provides MRF modules with scoped key-value storages to allow them to persist data across runs for things like counters or spam lists.
Kitsune provides MRF modules with scoped key-value storages to allow them to persist data across runs for things like counters or spam lists.

We provide multiple backends here:

Expand Down

0 comments on commit 8a746e4

Please sign in to comment.