mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-01-27 08:08:15 -05:00
feat(engine): set keep alive for Tokio threads (#16162)
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
//! Executor for mixed I/O and CPU workloads.
|
||||
|
||||
use rayon::ThreadPool as RayonPool;
|
||||
use std::sync::{Arc, OnceLock};
|
||||
use std::{
|
||||
sync::{Arc, OnceLock},
|
||||
time::Duration,
|
||||
};
|
||||
use tokio::{
|
||||
runtime::{Handle, Runtime},
|
||||
runtime::{Builder, Handle, Runtime},
|
||||
task::JoinHandle,
|
||||
};
|
||||
|
||||
@@ -66,10 +69,22 @@ impl WorkloadExecutorInner {
|
||||
fn new(rayon_pool: rayon::ThreadPool) -> Self {
|
||||
fn get_runtime_handle() -> Handle {
|
||||
Handle::try_current().unwrap_or_else(|_| {
|
||||
// Create a new runtime if now runtime is available
|
||||
// Create a new runtime if no runtime is available
|
||||
static RT: OnceLock<Runtime> = OnceLock::new();
|
||||
|
||||
let rt = RT.get_or_init(|| Runtime::new().unwrap());
|
||||
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()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user