sklears_compose/execution/
config.rs

1//! Configuration structures for the execution engine
2//!
3//! This module provides all configuration-related structures used by the
4//! composable execution engine.
5
6use std::collections::HashMap;
7use std::time::Duration;
8
9/// Configuration for the execution engine
10#[derive(Debug, Clone)]
11pub struct ExecutionEngineConfig {
12    /// Engine name
13    pub name: String,
14    /// Default execution strategy
15    pub default_strategy: String,
16    /// Resource constraints
17    pub resource_constraints: ResourceConstraints,
18    /// Performance goals
19    pub performance_goals: PerformanceGoals,
20    /// Fault tolerance settings
21    pub fault_tolerance: FaultToleranceConfig,
22    /// Monitoring configuration
23    pub monitoring: MonitoringConfig,
24}
25
26/// Resource constraints for execution
27#[derive(Debug, Clone)]
28pub struct ResourceConstraints {
29    /// Maximum CPU cores to use
30    pub max_cpu_cores: Option<usize>,
31    /// Maximum memory usage in bytes
32    pub max_memory: Option<u64>,
33    /// Maximum execution time per task
34    pub max_task_time: Option<Duration>,
35    /// Maximum concurrent tasks
36    pub max_concurrent_tasks: Option<usize>,
37    /// I/O bandwidth limits
38    pub io_bandwidth: Option<IoLimits>,
39}
40
41/// I/O bandwidth limits
42#[derive(Debug, Clone)]
43pub struct IoLimits {
44    pub max_read_bps: u64,
45    pub max_write_bps: u64,
46    pub max_concurrent_io: usize,
47}
48
49/// Performance goals for the execution engine
50#[derive(Debug, Clone)]
51pub struct PerformanceGoals {
52    /// Target throughput (tasks/sec)
53    pub target_throughput: f64,
54    /// Maximum acceptable latency
55    pub max_latency: Duration,
56    /// Target resource utilization (0.0-1.0)
57    pub target_utilization: f64,
58    /// Energy efficiency goals
59    pub energy_efficiency: Option<EnergyEfficiencyGoal>,
60}
61
62/// Energy efficiency goals
63#[derive(Debug, Clone)]
64pub struct EnergyEfficiencyGoal {
65    /// Target power consumption in watts
66    pub max_power_watts: f64,
67    /// Energy budget per task in joules
68    pub energy_budget_per_task: f64,
69}
70
71/// Fault tolerance configuration
72#[derive(Debug, Clone)]
73pub struct FaultToleranceConfig {
74    /// Enable retry on failure
75    pub enable_retry: bool,
76    /// Maximum number of retries
77    pub max_retries: usize,
78    /// Backoff strategy for retries
79    pub backoff_strategy: BackoffStrategy,
80    /// Enable circuit breaker
81    pub enable_circuit_breaker: bool,
82    /// Health check configuration
83    pub health_check: HealthCheckConfig,
84}
85
86/// Backoff strategy for retry operations
87#[derive(Debug, Clone)]
88pub enum BackoffStrategy {
89    /// Fixed delay between retries
90    Fixed { delay: Duration },
91    /// Exponential backoff with base delay
92    Exponential {
93        base_delay: Duration,
94        multiplier: f64,
95    },
96    /// Linear backoff with increment
97    Linear {
98        base_delay: Duration,
99        increment: Duration,
100    },
101    /// Custom backoff function
102    Custom { delays: Vec<Duration> },
103}
104
105/// Health check configuration
106#[derive(Debug, Clone)]
107pub struct HealthCheckConfig {
108    /// Health check interval
109    pub interval: Duration,
110    /// Timeout for health checks
111    pub timeout: Duration,
112    /// Number of consecutive failures before marking as unhealthy
113    pub failure_threshold: usize,
114    /// Number of consecutive successes before marking as healthy
115    pub success_threshold: usize,
116}
117
118/// Monitoring configuration
119#[derive(Debug, Clone)]
120pub struct MonitoringConfig {
121    /// Enable metrics collection
122    pub enable_metrics: bool,
123    /// Metrics collection interval
124    pub metrics_interval: Duration,
125    /// Enable distributed tracing
126    pub enable_tracing: bool,
127    /// Logging level
128    pub log_level: LogLevel,
129    /// Custom metric tags
130    pub metric_tags: HashMap<String, String>,
131}
132
133/// Logging levels
134#[derive(Debug, Clone)]
135pub enum LogLevel {
136    /// Trace
137    Trace,
138    /// Debug
139    Debug,
140    /// Info
141    Info,
142    /// Warn
143    Warn,
144    /// Error
145    Error,
146}
147
148/// Configuration for execution strategies
149#[derive(Debug, Clone)]
150pub struct StrategyConfig {
151    /// Strategy name
152    pub name: String,
153    /// Strategy parameters
154    pub parameters: HashMap<String, ParameterValue>,
155    /// Resource allocation for this strategy
156    pub resource_allocation: StrategyResourceAllocation,
157    /// Performance tuning settings
158    pub performance_tuning: PerformanceTuning,
159}
160
161/// Parameter values for strategy configuration
162#[derive(Debug, Clone)]
163pub enum ParameterValue {
164    /// String
165    String(String),
166    /// Integer
167    Integer(i64),
168    /// Float
169    Float(f64),
170    /// Boolean
171    Boolean(bool),
172    /// Duration
173    Duration(Duration),
174    /// List
175    List(Vec<ParameterValue>),
176}
177
178/// Resource allocation configuration for strategies
179#[derive(Debug, Clone)]
180pub struct StrategyResourceAllocation {
181    /// CPU core allocation
182    pub cpu_cores: f64,
183    /// Memory allocation in bytes
184    pub memory_bytes: u64,
185    /// Priority level (higher = more priority)
186    pub priority: u32,
187}
188
189/// Performance tuning configuration
190#[derive(Debug, Clone)]
191pub struct PerformanceTuning {
192    /// Optimization level
193    pub optimization_level: OptimizationLevel,
194    /// Enable prefetching
195    pub prefetching: PrefetchingStrategy,
196    /// Caching strategy
197    pub caching: CachingStrategy,
198    /// Load balancing configuration
199    pub load_balancing: LoadBalancingConfig,
200}
201
202/// Optimization levels
203#[derive(Debug, Clone)]
204pub enum OptimizationLevel {
205    None,
206    /// Low
207    Low,
208    /// Medium
209    Medium,
210    /// High
211    High,
212    /// Aggressive
213    Aggressive,
214}
215
216/// Prefetching strategies
217#[derive(Debug, Clone)]
218pub enum PrefetchingStrategy {
219    None,
220    /// Sequential
221    Sequential,
222    /// Adaptive
223    Adaptive,
224    /// Predictive
225    Predictive,
226}
227
228/// Caching strategies
229#[derive(Debug, Clone)]
230pub enum CachingStrategy {
231    None,
232    /// LRU
233    LRU,
234    /// LFU
235    LFU,
236    /// FIFO
237    FIFO,
238    /// Adaptive
239    Adaptive,
240}
241
242/// Load balancing configuration
243#[derive(Debug, Clone)]
244pub struct LoadBalancingConfig {
245    /// Enable load balancing
246    pub enabled: bool,
247    /// Load balancing algorithm
248    pub algorithm: LoadBalancingAlgorithm,
249    /// Rebalancing threshold
250    pub rebalance_threshold: f64,
251    /// Minimum load difference for rebalancing
252    pub min_load_difference: f64,
253}
254
255/// Load balancing algorithms
256#[derive(Debug, Clone)]
257pub enum LoadBalancingAlgorithm {
258    /// RoundRobin
259    RoundRobin,
260    /// LeastLoaded
261    LeastLoaded,
262    /// WeightedRoundRobin
263    WeightedRoundRobin,
264    /// ConsistentHashing
265    ConsistentHashing,
266    /// Random
267    Random,
268}
269
270impl Default for ExecutionEngineConfig {
271    fn default() -> Self {
272        Self {
273            name: "default-engine".to_string(),
274            default_strategy: "default".to_string(),
275            resource_constraints: ResourceConstraints::default(),
276            performance_goals: PerformanceGoals::default(),
277            fault_tolerance: FaultToleranceConfig::default(),
278            monitoring: MonitoringConfig::default(),
279        }
280    }
281}
282
283impl Default for ResourceConstraints {
284    fn default() -> Self {
285        Self {
286            max_cpu_cores: None,
287            max_memory: None,
288            max_task_time: Some(Duration::from_secs(300)), // 5 minutes
289            max_concurrent_tasks: Some(10),
290            io_bandwidth: None,
291        }
292    }
293}
294
295impl Default for PerformanceGoals {
296    fn default() -> Self {
297        Self {
298            target_throughput: 10.0, // 10 tasks/sec
299            max_latency: Duration::from_millis(100),
300            target_utilization: 0.8, // 80%
301            energy_efficiency: None,
302        }
303    }
304}
305
306impl Default for FaultToleranceConfig {
307    fn default() -> Self {
308        Self {
309            enable_retry: true,
310            max_retries: 3,
311            backoff_strategy: BackoffStrategy::Exponential {
312                base_delay: Duration::from_millis(100),
313                multiplier: 2.0,
314            },
315            enable_circuit_breaker: false,
316            health_check: HealthCheckConfig::default(),
317        }
318    }
319}
320
321impl Default for HealthCheckConfig {
322    fn default() -> Self {
323        Self {
324            interval: Duration::from_secs(30),
325            timeout: Duration::from_secs(5),
326            failure_threshold: 3,
327            success_threshold: 2,
328        }
329    }
330}
331
332impl Default for MonitoringConfig {
333    fn default() -> Self {
334        Self {
335            enable_metrics: true,
336            metrics_interval: Duration::from_secs(10),
337            enable_tracing: false,
338            log_level: LogLevel::Info,
339            metric_tags: HashMap::new(),
340        }
341    }
342}