@@ -12,6 +12,7 @@ use std::time::Duration;
1212use tokio:: time:: sleep;
1313
1414const DEFAULT_CONFIG_FILENAME : & str = "cloud_offloading.toml" ;
15+ const NODE_STABILIZATION_TIME_SECS : u64 = 120 ;
1516
1617#[ derive( Parser , Debug ) ]
1718#[ command( author, about, long_about = None ) ]
@@ -90,6 +91,7 @@ async fn run_cloud_offloading_delegated_orc(config: Config) -> anyhow::Result<()
9091 for node in cloud_nodes. iter_mut ( ) {
9192 if !node. active && active_orc_nodes. contains ( & node. node_id ) {
9293 node. active = true ;
94+ node. activation_time = Some ( std:: time:: Instant :: now ( ) ) ;
9395 log:: info!( "Cloud node {} is now active in the orchestrator!" , node. node_id) ;
9496 // After a node becomes active, we force a rebalance to ensure it receives load
9597 rebalancer. rebalance_cluster ( ) ;
@@ -138,7 +140,9 @@ async fn run_cloud_offloading_delegated_orc(config: Config) -> anyhow::Result<()
138140 // 2. DECIDE WHETHER TO CREATE A NEW NODE
139141 // Only create a new node if there isn't one already being created.
140142 // If the total number of active nodes is less than the minimum required, we also create a new node.
141- let is_creating_node = cloud_nodes. iter ( ) . any ( |n| !n. active ) ;
143+ let is_creating_node = cloud_nodes. iter ( ) . any ( |n| {
144+ !n. active || n. creation_time . elapsed ( ) . as_secs ( ) < NODE_STABILIZATION_TIME_SECS
145+ } ) ;
142146 if !is_creating_node
143147 && ( rebalancer. should_create_node (
144148 config. scaling . thresholds . credit_overload ,
@@ -182,9 +186,21 @@ async fn run_cloud_offloading_delegated_orc(config: Config) -> anyhow::Result<()
182186 // We only delete a node if there are more nodes available
183187 if active_orc_nodes. len ( ) > 1 {
184188 // If there's no node being created or emptied, check if we can find an underutilized node to delete
185- let managed_cloud_node_ids: HashSet < String > = cloud_nodes. iter ( ) . map ( |n| n. node_id . clone ( ) ) . collect ( ) ;
189+ // and consider only nodes that have been active for a certain stabilization time
190+ let stable_managed_node_ids: HashSet < String > = cloud_nodes
191+ . iter ( )
192+ . filter ( |n| {
193+ if let Some ( activation_time) = n. activation_time {
194+ activation_time. elapsed ( ) . as_secs ( ) >= NODE_STABILIZATION_TIME_SECS
195+ } else {
196+ true // If activation_time is None, consider it stable (it was never active)
197+ }
198+ } )
199+ . map ( |n| n. node_id . clone ( ) )
200+ . collect ( ) ;
201+
186202 if let Some ( victim_id) = rebalancer. find_node_to_delete (
187- & managed_cloud_node_ids ,
203+ & stable_managed_node_ids ,
188204 config. scaling . thresholds . cpu_low_percent ,
189205 config. scaling . thresholds . mem_low_percent ,
190206 ) {
0 commit comments