-
Notifications
You must be signed in to change notification settings - Fork 6
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -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); | ||||||||||
|
@@ -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. | ||||||||||
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); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My take:
Suggested change
|
||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
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) => { | ||||||||||
|
@@ -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); | ||||||||||
|
There was a problem hiding this comment.
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