node: Make worker count configurable

This commit is contained in:
Alexis Sellier 2024-03-19 16:34:15 +01:00
parent 6569449fff
commit ddd4bde302
No known key found for this signature in database
3 changed files with 17 additions and 4 deletions

View File

@ -49,6 +49,7 @@ $ rad config
"outbound": 16
}
},
"workers": 8,
"policy": "block",
"scope": "all"
}

View File

@ -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,

View File

@ -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
}
}