@@ -54,13 +54,11 @@ def main():
5454 # 4. predict replicas
5555 pred_replicas = predict_replicas (args , metrics_ctx , pred_traffics )
5656
57- # 5. resample predict replicas by scaling frequency
58- pred_replicas_by_freq = resample_by_freq (pred_replicas [['timestamp' , 'pred_replicas' ]],
59- args .scaling_freq ,
60- {'pred_replicas' : 'max' })
57+ # 5. adjust predict replicas by scaling frequency and scale up ahead seconds
58+ adjusted_pred_replicas = adjust_pred_replicas (args , pred_replicas )
6159
6260 # 6. write result to configmap
63- write_pred_replicas_to_config_map (args , env , hp_cr , pred_replicas_by_freq )
61+ write_pred_replicas_to_config_map (args , env , hp_cr , adjusted_pred_replicas )
6462
6563 return
6664
@@ -96,6 +94,9 @@ def parse_args():
9694 parser .add_argument ('--scaling-freq' , help = 'frequency of scaling, the duration should be larger than the frequency'
9795 'of the time series forecasting model' ,
9896 required = True )
97+ parser .add_argument ('--scale-up-ahead-seconds' , help = 'ahead time seconds of scaling up which can be used for'
98+ 'application startup and warm up' ,
99+ required = False , default = 0 )
99100 args = parser .parse_args ()
100101 return args
101102
@@ -162,6 +163,16 @@ def merge_history_dict(history_dict):
162163 return df
163164
164165
166+ def adjust_pred_replicas (args , pred_replicas ):
167+ adjusted = resample_by_freq (pred_replicas [['timestamp' , 'pred_replicas' ]],
168+ args .scaling_freq ,
169+ {'pred_replicas' : 'max' })
170+ scale_up_ahead_seconds = int (args .scale_up_ahead_seconds )
171+ if scale_up_ahead_seconds > 0 :
172+ adjusted .loc [adjusted ['pred_replicas' ] > adjusted ['pred_replicas' ].shift (1 ), 'timestamp' ] -= scale_up_ahead_seconds
173+ return adjusted
174+
175+
165176def resample_by_freq (old_df , freq , agg_funcs ):
166177 df = old_df .sort_values (by = 'timestamp' , ascending = True )
167178 df ['timestamp' ] = pd .to_datetime (df ['timestamp' ], unit = 's' )
0 commit comments