mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-04-08 03:01:12 -04:00
chore: name tokio rt threads (#21777)
This commit is contained in:
@@ -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() }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user