omni_orchestrator/worker_autoscaler/
policy.rs1use std::collections::HashMap;
2use std::time::Duration;
3use serde::{Serialize, Deserialize};
4
5use super::metrics::MetricThreshold;
6
7#[derive(Debug, Clone, Serialize, Deserialize)]
9pub struct ScalingPolicy {
10 pub max_worker_count: usize,
12 pub min_worker_count: usize,
14 pub cooldown_period: Duration,
16 pub metrics_thresholds: HashMap<String, MetricThreshold>,
18 pub scale_up_increment: usize,
20 pub scale_down_increment: usize,
22 pub scale_down_delay: Duration,
24 pub max_scale_down_percentage: f32,
26 pub autoscaling_enabled: bool,
28}
29
30impl Default for ScalingPolicy {
31 fn default() -> Self {
32 Self {
33 max_worker_count: 10,
34 min_worker_count: 1,
35 cooldown_period: Duration::from_secs(300), metrics_thresholds: HashMap::new(),
37 scale_up_increment: 1,
38 scale_down_increment: 1,
39 scale_down_delay: Duration::from_secs(600), max_scale_down_percentage: 0.25, autoscaling_enabled: true,
42 }
43 }
44}
45
46pub fn create_default_cpu_memory_scaling_policy() -> ScalingPolicy {
48 let mut policy = ScalingPolicy::default();
49
50 let mut thresholds = HashMap::new();
51 thresholds.insert("cpu_utilization".to_string(), MetricThreshold::Float(70.0));
52 thresholds.insert("memory_utilization".to_string(), MetricThreshold::Float(80.0));
53
54 policy.metrics_thresholds = thresholds;
55 policy
56}