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

Stop all actors at once instead of stopping/joining threads sequentially #85

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
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
24 changes: 17 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,8 @@ impl Deref for System {
impl SystemHandle {
/// Stops all actors spawned by this system.
pub fn shutdown(&self) -> Result<(), ActorError> {
let shutdown_start = Instant::now();

let current_thread = thread::current();
let current_thread_name = current_thread.name().unwrap_or("Unknown thread id");
info!("Thread [{}] shutting down the actor system", current_thread_name);
Expand Down Expand Up @@ -656,18 +658,26 @@ impl SystemHandle {
let err_count = {
let mut registry = self.registry.lock();
debug!("[{}] joining {} actor threads.", self.name, registry.len());
// Joining actors in the reverse order in which they are spawn.

// Stopping actors in the reverse order in which they were spawned.
// We send the Stop control message to all actors first so they can
// all shut down in parallel, so actors will be in the process of
// stopping when we join the threads below.
Comment on lines +662 to +665
Copy link
Member

Choose a reason for hiding this comment

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

tiny nit present simple, imperative form of comments

Suggested change
// Stopping actors in the reverse order in which they were spawned.
// We send the Stop control message to all actors first so they can
// all shut down in parallel, so actors will be in the process of
// stopping when we join the threads below.
// Stop actors in the reverse order in which they were spawned.
// Send the Stop control message to all actors first so they can
// all shut down in parallel, so actors will be in the process of
// stopping when we join the threads below.

for entry in registry.iter_mut().rev() {
let actor_name = entry.name();

if let Err(e) = entry.control_addr().send(Control::Stop) {
warn!("control channel is closed: {} ({})", actor_name, e);
Copy link
Member

Choose a reason for hiding this comment

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

Preexisting, but It'd be nice to mention a context where this is happening and the consequence (to please @strohel). For instance:

Suggested change
warn!("control channel is closed: {} ({})", actor_name, e);
warn!("Couldn't send Control::Stop to {} to shut it down. Proceeding to shut down remaining actors: {}", actor_name, e);

Copy link
Contributor

Choose a reason for hiding this comment

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

The new wording is confusing to me, the error message should come after the first sentence, not the second one. I'd just remove the "Proceeding" sentence.

Copy link
Member

Choose a reason for hiding this comment

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

My take:

Suggested change
warn!("control channel is closed: {} ({})", actor_name, e);
warn!("Couldn't send Control::Stop to {} to shut it down: {}. Ignoring and proceeding.", actor_name, e);

}
}

registry
.drain(..)
.rev()
.enumerate()
.filter_map(|(i, mut entry)| {
.filter_map(|(i, entry)| {
let actor_name = entry.name();

if let Err(e) = entry.control_addr().send(Control::Stop) {
warn!("control channel is closed: {} ({})", actor_name, e);
}

match entry {
RegistryEntry::CurrentThread(_) => None,
RegistryEntry::BackgroundThread(_control_addr, thread_handle) => {
Expand All @@ -689,7 +699,7 @@ impl SystemHandle {
.count()
};

info!("[{}] system finished shutting down.", self.name);
info!("[{}] system finished shutting down in {:?}", self.name, shutdown_start.elapsed());

if let Some(callback) = self.callbacks.postshutdown.as_ref() {
info!("[{}] calling post-shutdown callback.", self.name);
Expand Down
Loading