Rust · 1781 bytes Raw Blame History
1 //! Contribution-Based Load Balancer
2 //!
3 //! Load balancing based on node contribution and performance rather than cost
4
5 use anyhow::Result;
6 use serde::{Deserialize, Serialize};
7 use std::collections::HashMap;
8 use chrono::{DateTime, Utc};
9
10 /// Load balancer using contribution metrics
11 #[derive(Debug, Clone, Serialize, Deserialize)]
12 pub struct ContributionLoadBalancer {
13 pub load_balancing_decisions: Vec<LoadBalancingDecision>,
14 pub resource_weights: HashMap<String, ResourceWeight>,
15 pub routing_cache: HashMap<String, OptimizedRouting>,
16 }
17
18 #[derive(Debug, Clone, Serialize, Deserialize)]
19 pub struct LoadBalancingDecision {
20 pub decision_id: String,
21 pub selected_nodes: Vec<String>,
22 pub load_distribution: HashMap<String, f64>,
23 pub decision_time: DateTime<Utc>,
24 }
25
26 #[derive(Debug, Clone, Serialize, Deserialize)]
27 pub struct ResourceWeight {
28 pub node_id: String,
29 pub contribution_weight: f64,
30 pub performance_weight: f64,
31 pub reliability_weight: f64,
32 pub total_weight: f64,
33 }
34
35 #[derive(Debug, Clone, Serialize, Deserialize)]
36 pub struct OptimizedRouting {
37 pub route_id: String,
38 pub primary_nodes: Vec<String>,
39 pub backup_nodes: Vec<String>,
40 pub expected_performance: f64,
41 }
42
43 #[derive(Debug, Clone, Serialize, Deserialize)]
44 pub struct PerformanceAllocation {
45 pub allocation_id: String,
46 pub performance_target: f64,
47 pub actual_performance: f64,
48 pub nodes_used: Vec<String>,
49 }
50
51 impl ContributionLoadBalancer {
52 pub fn new() -> Self {
53 Self {
54 load_balancing_decisions: Vec::new(),
55 resource_weights: HashMap::new(),
56 routing_cache: HashMap::new(),
57 }
58 }
59 }
60
61 impl Default for ContributionLoadBalancer {
62 fn default() -> Self {
63 Self::new()
64 }
65 }