diff --git a/radicle-cli/examples/rad-config.md b/radicle-cli/examples/rad-config.md index 8fcbf4d9..9a323433 100644 --- a/radicle-cli/examples/rad-config.md +++ b/radicle-cli/examples/rad-config.md @@ -49,6 +49,7 @@ $ rad config "outbound": 16 } }, + "workers": 8, "policy": "block", "scope": "all" } diff --git a/radicle-node/src/runtime.rs b/radicle-node/src/runtime.rs index bd6be433..f3d2a158 100644 --- a/radicle-node/src/runtime.rs +++ b/radicle-node/src/runtime.rs @@ -222,7 +222,7 @@ impl Runtime { let emitter: Emitter = Default::default(); let mut service = service::Service::new( - config, + config.clone(), clock, db, storage.clone(), @@ -261,7 +261,7 @@ impl Runtime { notifications, cobs_cache, worker::Config { - capacity: 8, + capacity: config.workers, storage: storage.clone(), fetch, policy, diff --git a/radicle/src/node/config.rs b/radicle/src/node/config.rs index 6c235340..02ddd835 100644 --- a/radicle/src/node/config.rs +++ b/radicle/src/node/config.rs @@ -11,6 +11,8 @@ use crate::node::{Address, Alias, NodeId}; /// Target number of peers to maintain connections to. pub const TARGET_OUTBOUND_PEERS: usize = 8; +/// Default number of workers to spawn. +pub const DEFAULT_WORKERS: usize = 8; /// Configured public seeds. pub mod seeds { @@ -246,6 +248,9 @@ pub struct Config { /// Configured service limits. #[serde(default)] pub limits: Limits, + /// Number of worker threads to spawn. + #[serde(default = "defaults::workers")] + pub workers: usize, /// Default seeding policy. #[serde(default)] pub policy: Policy, @@ -272,13 +277,12 @@ impl Config { network: Network::default(), relay: true, limits: Limits::default(), + workers: DEFAULT_WORKERS, policy: Policy::default(), scope: Scope::default(), } } -} -impl Config { pub fn peer(&self, id: &NodeId) -> Option<&Address> { self.connect .iter() @@ -294,3 +298,11 @@ impl Config { node::Features::SEED } } + +/// Defaults as functions, for serde. +mod defaults { + /// Worker count. + pub fn workers() -> usize { + super::DEFAULT_WORKERS + } +}