mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-01-10 07:48:19 -05:00
feat(tasks): add thread names for spawned blocking tasks
Closes #20430 by adding descriptive thread names to blocking task pools, making them identifiable in profilers like Samply. Thread naming convention (kept under 15-char Linux limit): - reth-node-{idx}: Main node runtime threads - reth-eng-{idx}: Engine WorkloadExecutor threads - reth-blk-{idx}: BlockingTaskPool rayon threads
This commit is contained in:
@@ -214,7 +214,16 @@ pub struct CliContext {
|
||||
/// Creates a new default tokio multi-thread [Runtime](tokio::runtime::Runtime) with all features
|
||||
/// enabled
|
||||
pub fn tokio_runtime() -> Result<tokio::runtime::Runtime, std::io::Error> {
|
||||
tokio::runtime::Builder::new_multi_thread().enable_all().build()
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
static THREAD_IDX: AtomicUsize = AtomicUsize::new(0);
|
||||
|
||||
tokio::runtime::Builder::new_multi_thread()
|
||||
.enable_all()
|
||||
.thread_name_fn(|| {
|
||||
let idx = THREAD_IDX.fetch_add(1, Ordering::Relaxed);
|
||||
format!("reth-node-{idx}")
|
||||
})
|
||||
.build()
|
||||
}
|
||||
|
||||
/// Runs the given future to completion or until a critical task panicked.
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
//! Executor for mixed I/O and CPU workloads.
|
||||
|
||||
use std::{sync::OnceLock, time::Duration};
|
||||
use std::{
|
||||
sync::{
|
||||
atomic::{AtomicUsize, Ordering},
|
||||
OnceLock,
|
||||
},
|
||||
time::Duration,
|
||||
};
|
||||
use tokio::{
|
||||
runtime::{Builder, Handle, Runtime},
|
||||
task::JoinHandle,
|
||||
@@ -51,6 +57,8 @@ impl WorkloadExecutorInner {
|
||||
static RT: OnceLock<Runtime> = OnceLock::new();
|
||||
|
||||
let rt = RT.get_or_init(|| {
|
||||
static THREAD_IDX: AtomicUsize = AtomicUsize::new(0);
|
||||
|
||||
Builder::new_multi_thread()
|
||||
.enable_all()
|
||||
// Keep the threads alive for at least the block time, which is 12 seconds
|
||||
@@ -60,6 +68,10 @@ impl WorkloadExecutorInner {
|
||||
// new block, and instead reuse the existing
|
||||
// threads.
|
||||
.thread_keep_alive(Duration::from_secs(15))
|
||||
.thread_name_fn(|| {
|
||||
let idx = THREAD_IDX.fetch_add(1, Ordering::Relaxed);
|
||||
format!("reth-eng-{idx}")
|
||||
})
|
||||
.build()
|
||||
.unwrap()
|
||||
});
|
||||
|
||||
@@ -73,7 +73,7 @@ impl BlockingTaskPool {
|
||||
/// If a different stack size or other parameters are needed, they can be configured via
|
||||
/// [`rayon::ThreadPoolBuilder`] returned by [`Self::builder`].
|
||||
pub fn build() -> Result<Self, rayon::ThreadPoolBuildError> {
|
||||
Self::builder().build().map(Self::new)
|
||||
Self::builder().thread_name(|i| format!("reth-blk-{i}")).build().map(Self::new)
|
||||
}
|
||||
|
||||
/// Asynchronous wrapper around Rayon's
|
||||
|
||||
Reference in New Issue
Block a user