fn do_downscaling(
        &self,
        _stats: &mut ActorGroupStats,
        actors: &FxHashMap<BastionId, (Sender, RecoverableHandle<()>)>,
    ) -> Option<ScalingRule> {
        let mut actors_to_stop = Vec::new();
        for (actor_id, (_, handle)) in actors {
            let state = handle.state();

            // TODO: Enable this check when the following issue will be resolved
            // link: https://github.com/bastion-rs/bastion/issues/236
            // let mailbox_size = self.actor_stats.get(actor_id).unwrap_or(0);
            // let can_be_freed = mailbox_size == 0 && state.is_pending();

            if state.is_closed() || state.is_completed() {
                actors_to_stop.push(actor_id.clone())
            }
        }
        if !actors_to_stop.is_empty() {
            let active_actors_count = actors.len();
            let freed_actors_limit =
                (self.downscale_rate * active_actors_count as f64).ceil() as usize;
            let mut freed_actors_desired = min(actors_to_stop.len(), freed_actors_limit);
            let left_active_actors = active_actors_count - freed_actors_desired;

            // Make sure here that we won't exceed the limits while stopping actors
            freed_actors_desired = match left_active_actors >= self.lower_bound as usize {
                true => freed_actors_desired,
                false => {
                    let excessive_actors_to_stop = self.lower_bound as usize - left_active_actors;
                    freed_actors_desired - excessive_actors_to_stop
                }
            };
            return match freed_actors_desired {
                0 => Some(ScalingRule::DoNothing),
                _ => {
                    let freed_actors = actors_to_stop.drain(0..freed_actors_desired).collect();
                    Some(ScalingRule::Downscale(freed_actors))
                }
            };
        }

        None
    }
// Scaling down: stop and remove actors that killed, stopped or successfully
// finished up its own execution.
Scaling down: stop and remove actors that killed, stopped or successfully
finished up its own execution.
Scaling down : stop and remove actors that killed stopped or successfully finished up its own execution .
fn do_downscaling(
        &self,
        _stats: &mut ActorGroupStats,
        actors: &FxHashMap<BastionId, (Sender, RecoverableHandle<()>)>,
    ) -> Option<ScalingRule> {
        let mut actors_to_stop = Vec::new();
        for (actor_id, (_, handle)) in actors {
            let state = handle.state();
            // TODO: Enable this check when the following issue will be resolved
            // link: https://github.com/bastion-rs/bastion/issues/236
            // let mailbox_size = self.actor_stats.get(actor_id).unwrap_or(0);
            // let can_be_freed = mailbox_size == 0 && state.is_pending();
            if state.is_closed() || state.is_completed() {
                actors_to_stop.push(actor_id.clone())
            }
        }
        if !actors_to_stop.is_empty() {
            let active_actors_count = actors.len();
            let freed_actors_limit =
                (self.downscale_rate * active_actors_count as f64).ceil() as usize;
            let mut freed_actors_desired = min(actors_to_stop.len(), freed_actors_limit);
            let left_active_actors = active_actors_count - freed_actors_desired;
            // Make sure here that we won't exceed the limits while stopping actors
            freed_actors_desired = match left_active_actors >= self.lower_bound as usize {
                true => freed_actors_desired,
                false => {
                    let excessive_actors_to_stop = self.lower_bound as usize - left_active_actors;
                    freed_actors_desired - excessive_actors_to_stop
                }
            };
            return match freed_actors_desired {
                0 => Some(ScalingRule::DoNothing),
                _ => {
                    let freed_actors = actors_to_stop.drain(0..freed_actors_desired).collect();
                    Some(ScalingRule::Downscale(freed_actors))
                }
            };
        }
        None
    }
fn do_downscaling ( & self , _stats : & mut ActorGroupStats , actors : & FxHashMap < BastionId , ( Sender , RecoverableHandle < ( ) > ) > , ) -> Option < ScalingRule > { let mut actors_to_stop = Vec :: new ( ) ; for ( actor_id , ( _ , handle ) ) in actors { let state = handle . state ( ) ; // TODO: Enable this check when the following issue will be resolved // link: https://github.com/bastion-rs/bastion/issues/236 // let mailbox_size = self.actor_stats.get(actor_id).unwrap_or(0); // let can_be_freed = mailbox_size == 0 && state.is_pending(); if state . is_closed ( ) || state . is_completed ( ) { actors_to_stop . push ( actor_id . clone ( ) ) } } if ! actors_to_stop . is_empty ( ) { let active_actors_count = actors . len ( ) ; let freed_actors_limit = ( self . downscale_rate * active_actors_count as f64 ) . ceil ( ) as usize ; let mut freed_actors_desired = min ( actors_to_stop . len ( ) , freed_actors_limit ) ; let left_active_actors = active_actors_count - freed_actors_desired ; // Make sure here that we won't exceed the limits while stopping actors freed_actors_desired = match left_active_actors >= self . lower_bound as usize { true => freed_actors_desired , false => { let excessive_actors_to_stop = self . lower_bound as usize - left_active_actors ; freed_actors_desired - excessive_actors_to_stop } } ; return match freed_actors_desired { 0 => Some ( ScalingRule :: DoNothing ) , _ => { let freed_actors = actors_to_stop . drain ( 0 .. freed_actors_desired ) . collect ( ) ; Some ( ScalingRule :: Downscale ( freed_actors ) ) } } ; } None }
Scaling down: stop and remove actors that killed, stopped or successfully
finished up its own execution.
Scaling down : stop and remove actors that killed stopped or successfully finished up its own execution .
&self
_stats
&mut ActorGroupStats
actors
&FxHashMap<BastionId, (Sender, RecoverableHandle<()>)>
&self
_stats
&mut ActorGroupStats
actors
&FxHashMap<BastionId, (Sender, RecoverableHandle<()>)>