Radish alpha
h
rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5
Radicle Heartwood Protocol & Stack
Radicle
Git
node: Make worker count configurable
Merged did:key:z6MktaNv...ZRZW opened 2 years ago
3 files changed +17 -4 6569449f ddd4bde3
modified radicle-cli/examples/rad-config.md
@@ -49,6 +49,7 @@ $ rad config
        "outbound": 16
      }
    },
+
    "workers": 8,
    "policy": "block",
    "scope": "all"
  }
modified radicle-node/src/runtime.rs
@@ -222,7 +222,7 @@ impl Runtime {

        let emitter: Emitter<Event> = 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,
modified 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
+
    }
+
}