From 6d3dbcb129b67152c89bbbe2a7dad98b071bf838 Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 1 Dec 2026 13:19:32 +0000 Subject: Two options for a node on a machine that should idle --libp2p-ping-interval: how often libp2p pings each open connection, 15 s unless given, 0 for once as it opens. The pings keep no connection open and close none; continuum takes each connection's round trip from them, to keep the fastest of several to one peer. --worker-threads: how many threads take the node's work in turns, as many as the machine has cores unless given. The runtime is built from the configuration, so the count is set as the node starts. Each wakes the node's threads less often; docs/operations.md, An idle node, says what to choose, and what was measured. --- src/lib.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index a420555..8668347 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -77,8 +77,9 @@ fn voter(args: &config::Settings) -> Result> { })) } -/// Runs a node, as its arguments and configuration say, until it stops. -pub async fn run() -> Result<()> { +/// Runs a node, as its arguments and configuration say, until it stops: on a runtime +/// of as many worker threads as `--worker-threads` says, or as the machine has cores. +pub fn main() -> Result<()> { logging::init(); if let Some((file, create)) = config::asked_node_id() { @@ -98,6 +99,19 @@ pub async fn run() -> Result<()> { ); return Ok(()); } + let mut runtime = tokio::runtime::Builder::new_multi_thread(); + runtime.enable_all(); + if let Some(threads) = config.settings.worker_threads { + runtime.worker_threads(threads); + } + runtime + .build() + .context("Starting the runtime")? + .block_on(run(config)) +} + +/// Runs the node `config` describes, until it stops. +async fn run(config: config::Loaded) -> Result<()> { let args = &config.settings; if let Some(format) = logging::LogFormat::parse(&args.log_format) { logging::set_format(format); -- cgit v1.3.1