Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thread manager instantiation in the validator #4603

Merged
merged 5 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions core/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ pub struct Validator {
repair_quic_endpoints: Option<[Endpoint; 3]>,
repair_quic_endpoints_runtime: Option<TokioRuntime>,
repair_quic_endpoints_join_handle: Option<repair::quic_endpoint::AsyncTryJoinHandle>,
_thread_manager: ThreadManager,
thread_manager: ThreadManager,
}

impl Validator {
Expand Down Expand Up @@ -1664,7 +1664,7 @@ impl Validator {
repair_quic_endpoints,
repair_quic_endpoints_runtime,
repair_quic_endpoints_join_handle,
_thread_manager: thread_manager,
thread_manager,
})
}

Expand Down Expand Up @@ -1822,6 +1822,7 @@ impl Validator {
self.poh_timing_report_service
.join()
.expect("poh_timing_report_service");
self.thread_manager.destroy();
}
}

Expand Down
35 changes: 32 additions & 3 deletions thread-manager/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
use {
anyhow::Ok,
std::{collections::HashMap, ops::Deref, sync::Arc},
log::{debug, error, warn},
std::{
collections::HashMap,
ops::Deref,
sync::{atomic::Ordering, Arc},
},
};

pub mod config;
Expand Down Expand Up @@ -87,7 +91,7 @@ impl ThreadManager {
Some(n) => runtimes.get(n),
None => match mapping.get("default") {
Some(n) => {
log::warn!("Falling back to default runtime for {name}");
warn!("Falling back to default runtime for {name}");
runtimes.get(n)
}
None => None,
Expand Down Expand Up @@ -164,6 +168,31 @@ impl ThreadManager {
inner: Arc::new(manager),
})
}

pub fn destroy(self) {
let Ok(mut inner) = Arc::try_unwrap(self.inner) else {
error!(
"References to Thread Manager are still active, clean shutdown may not be possible!"
);
return;
};

for (name, runtime) in inner.tokio_runtimes.drain() {
let active_cnt = runtime.counters.active_threads_cnt.load(Ordering::SeqCst);
match active_cnt {
0 => debug!("Shutting down Tokio runtime {name}"),
_ => warn!("Tokio runtime {name} has active workers during shutdown!"),
}
runtime.tokio.shutdown_background();
}
for (name, runtime) in inner.native_thread_runtimes.drain() {
let active_cnt = runtime.running_count.load(Ordering::SeqCst);
match active_cnt {
0 => debug!("Shutting down Native thread pool {name}"),
_ => warn!("Native pool {name} has active threads during shutdown!"),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be useful for debug to include number of threads still active

}
}
}
}

#[cfg(test)]
Expand Down
Loading