chore: name tokio rt threads (#21777)

This commit is contained in:
DaniPopes
2026-02-04 16:23:22 +01:00
committed by GitHub
parent 1fc3d2c4ae
commit a3f7431d28
3 changed files with 16 additions and 33 deletions

View File

@@ -1,10 +1,7 @@
//! Executor for mixed I/O and CPU workloads.
use std::{sync::OnceLock, time::Duration};
use tokio::{
runtime::{Builder, Handle, Runtime},
task::JoinHandle,
};
use reth_trie_parallel::root::get_tokio_runtime_handle;
use tokio::{runtime::Handle, task::JoinHandle};
/// An executor for mixed I/O and CPU workloads.
///
@@ -27,7 +24,7 @@ impl WorkloadExecutor {
&self.inner.handle
}
/// Shorthand for [`Runtime::spawn_blocking`]
/// Runs the provided function on an executor dedicated to blocking operations.
#[track_caller]
pub fn spawn_blocking<F, R>(&self, func: F) -> JoinHandle<R>
where
@@ -45,29 +42,6 @@ struct WorkloadExecutorInner {
impl WorkloadExecutorInner {
fn new() -> Self {
fn get_runtime_handle() -> Handle {
Handle::try_current().unwrap_or_else(|_| {
// Create a new runtime if no runtime is available
static RT: OnceLock<Runtime> = OnceLock::new();
let rt = RT.get_or_init(|| {
Builder::new_multi_thread()
.enable_all()
// Keep the threads alive for at least the block time, which is 12 seconds
// at the time of writing, plus a little extra.
//
// This is to prevent the costly process of spawning new threads on every
// new block, and instead reuse the existing
// threads.
.thread_keep_alive(Duration::from_secs(15))
.build()
.unwrap()
});
rt.handle().clone()
})
}
Self { handle: get_runtime_handle() }
Self { handle: get_tokio_runtime_handle() }
}
}