Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions crates/cli/src/subcommands/subscribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ enum Error {
},
#[error("encountered failed transaction: {reason}")]
TransactionFailure { reason: Box<str> },
#[error("encountered error in initial subscribe: {reason}")]
SubscribeFailure { reason: Box<str> },
Comment thread
joshua-spacetime marked this conversation as resolved.
#[error("error formatting response: {source:#}")]
Reformat {
#[source]
Expand Down Expand Up @@ -295,6 +297,9 @@ where
}
break;
}
ws_v1::ServerMessage::SubscriptionError(error) => {
return Err(Error::SubscribeFailure { reason: error.error });
}
ws_v1::ServerMessage::TransactionUpdate(ws_v1::TransactionUpdate { status, .. }) => {
return Err(match status {
ws_v1::UpdateStatus::Failed(msg) => Error::TransactionFailure { reason: msg },
Expand Down Expand Up @@ -341,6 +346,9 @@ where
details: "received a second initial subscription update",
})
}
ws_v1::ServerMessage::SubscriptionError(error) => {
return Err(Error::SubscribeFailure { reason: error.error });
}
ws_v1::ServerMessage::TransactionUpdateLight(ws_v1::TransactionUpdateLight { update, .. })
| ws_v1::ServerMessage::TransactionUpdate(ws_v1::TransactionUpdate {
status: ws_v1::UpdateStatus::Committed(update),
Expand Down
49 changes: 49 additions & 0 deletions crates/core/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ impl fmt::Display for MetadataFile {
pub struct ConfigFile {
pub certificate_authority: Option<CertificateAuthority>,
pub logs: LogConfig,
pub wasm: WasmConfig,
pub v8: V8Config,
}

Expand All @@ -148,6 +149,8 @@ struct ConfigFileToml {
#[serde(default)]
logs: LogConfig,
#[serde(default)]
wasm: WasmConfigToml,
#[serde(default)]
v8: V8ConfigToml,
#[serde(default)]
v8_heap_policy: V8HeapPolicyConfig,
Expand All @@ -162,6 +165,9 @@ impl<'de> serde::Deserialize<'de> for ConfigFile {
Ok(Self {
certificate_authority: config.certificate_authority,
logs: config.logs,
wasm: WasmConfig {
procedure_instance_pool_size: config.wasm.procedure_instance_pool_size,
},
v8: V8Config {
procedure_instance_pool_size: config.v8.procedure_instance_pool_size,
heap_policy: config.v8_heap_policy,
Expand Down Expand Up @@ -206,6 +212,37 @@ pub struct LogConfig {
pub directives: Vec<String>,
}

#[derive(Clone, Copy, Debug)]
pub struct WasmConfig {
pub procedure_instance_pool_size: NonZeroUsize,
}

impl Default for WasmConfig {
fn default() -> Self {
Self {
procedure_instance_pool_size: default_wasm_procedure_instance_pool_size(),
}
}
}

#[derive(Clone, Copy, Debug, serde::Deserialize)]
#[serde(rename_all = "kebab-case")]
struct WasmConfigToml {
#[serde(
default = "default_wasm_procedure_instance_pool_size",
deserialize_with = "de_nz_usize"
)]
pub procedure_instance_pool_size: NonZeroUsize,
}

impl Default for WasmConfigToml {
fn default() -> Self {
Self {
procedure_instance_pool_size: default_wasm_procedure_instance_pool_size(),
}
}
}

#[derive(Clone, Copy, Debug)]
pub struct V8Config {
pub procedure_instance_pool_size: NonZeroUsize,
Expand Down Expand Up @@ -323,6 +360,10 @@ fn default_v8_procedure_instance_pool_size() -> NonZeroUsize {
std::thread::available_parallelism().unwrap_or_else(|_| NonZeroUsize::new(1).unwrap())
}

fn default_wasm_procedure_instance_pool_size() -> NonZeroUsize {
std::thread::available_parallelism().unwrap_or_else(|_| NonZeroUsize::new(1).unwrap())
}

fn de_nz_usize<'de, D>(deserializer: D) -> Result<NonZeroUsize, D::Error>
where
D: serde::Deserializer<'de>,
Expand Down Expand Up @@ -521,6 +562,10 @@ mod tests {
fn v8_heap_policy_defaults_when_omitted() {
let config: ConfigFile = toml::from_str("").unwrap();

assert_eq!(
config.wasm.procedure_instance_pool_size,
default_wasm_procedure_instance_pool_size()
);
assert_eq!(
config.v8.procedure_instance_pool_size,
default_v8_procedure_instance_pool_size()
Expand All @@ -538,6 +583,9 @@ mod tests {
#[test]
fn v8_heap_policy_parses_from_toml() {
let toml = r#"
[wasm]
procedure-instance-pool-size = 4

[v8]
procedure-instance-pool-size = 3

Expand All @@ -551,6 +599,7 @@ mod tests {

let config: ConfigFile = toml::from_str(toml).unwrap();

assert_eq!(config.wasm.procedure_instance_pool_size.get(), 4);
assert_eq!(config.v8.procedure_instance_pool_size.get(), 3);
assert_eq!(config.v8.heap_policy.heap_check_request_interval, None);
assert_eq!(
Expand Down
26 changes: 19 additions & 7 deletions crates/core/src/host/host_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use super::scheduler::SchedulerStarter;
use super::wasmtime::WasmtimeRuntime;
use super::{Scheduler, UpdateDatabaseResult};
use crate::client::{ClientActorId, ClientName};
use crate::config::V8Config;
use crate::config::{V8Config, WasmConfig};
use crate::database_logger::DatabaseLogger;
use crate::db::persistence::PersistenceProvider;
use crate::db::relational_db::{self, spawn_view_cleanup_loop, DiskSizeFn, RelationalDB, Txdata};
Expand Down Expand Up @@ -124,10 +124,22 @@ pub(crate) struct HostRuntimes {
v8: V8Runtime,
}

#[derive(Clone, Copy, Debug, Default)]
pub struct HostRuntimeConfig {
pub wasm: WasmConfig,
pub v8: V8Config,
}

impl HostRuntimeConfig {
pub fn new(wasm: WasmConfig, v8: V8Config) -> Self {
Self { wasm, v8 }
}
}

impl HostRuntimes {
fn new(data_dir: Option<&ServerDataDir>, v8_config: V8Config) -> Arc<Self> {
let wasmtime = WasmtimeRuntime::new(data_dir);
let v8 = V8Runtime::new(v8_config);
fn new(data_dir: Option<&ServerDataDir>, config: HostRuntimeConfig) -> Arc<Self> {
let wasmtime = WasmtimeRuntime::new(data_dir, config.wasm);
let v8 = V8Runtime::new(config.v8);
Arc::new(Self { wasmtime, v8 })
}
}
Expand Down Expand Up @@ -211,7 +223,7 @@ impl HostController {
pub fn new(
data_dir: Arc<ServerDataDir>,
default_config: db::Config,
v8_config: V8Config,
runtime_config: HostRuntimeConfig,
program_storage: ProgramStorage,
energy_monitor: Arc<impl EnergyMonitor>,
persistence: Arc<dyn PersistenceProvider>,
Expand All @@ -223,7 +235,7 @@ impl HostController {
program_storage,
energy_monitor,
persistence,
runtimes: HostRuntimes::new(Some(&data_dir), v8_config),
runtimes: HostRuntimes::new(Some(&data_dir), runtime_config),
data_dir,
page_pool: PagePool::new(default_config.page_pool_max_size),
bsatn_rlb_pool: BsatnRowListBuilderPool::new(),
Expand Down Expand Up @@ -1365,7 +1377,7 @@ pub async fn extract_schema(program_bytes: Box<[u8]>, host_type: HostType) -> an
extract_schema_with_pools(
PagePool::new(None),
BsatnRowListBuilderPool::new(),
&HostRuntimes::new(None, V8Config::default()),
&HostRuntimes::new(None, HostRuntimeConfig::default()),
program_bytes,
host_type,
)
Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/host/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ mod wasm_common;
pub use disk_storage::DiskStorage;
pub use host_controller::{
extract_schema, CallProcedureReturn, CallResult, ExternalDurability, ExternalStorage, HostController,
MigratePlanResult, ProcedureCallResult, ProgramStorage, ReducerCallResult, ReducerOutcome,
HostRuntimeConfig, MigratePlanResult, ProcedureCallResult, ProgramStorage, ReducerCallResult, ReducerOutcome,
};
pub use module_host::{ModuleHost, NoSuchModule, ProcedureCallError, ReducerCallError, UpdateDatabaseResult};
pub use scheduler::Scheduler;
Expand Down
Loading
Loading