Skip to main content

entrenar/efficiency/platform/
server.rs

1//! Server deployment efficiency metrics.
2
3use serde::{Deserialize, Serialize};
4
5/// Server deployment efficiency metrics
6#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7pub struct ServerEfficiency {
8    /// Training/inference throughput in samples per second
9    pub throughput_samples_per_sec: f64,
10    /// GPU utilization percentage (0-100)
11    pub gpu_utilization_percent: f64,
12    /// Memory bandwidth in GB/s
13    pub memory_bandwidth_gbps: f64,
14}
15
16impl ServerEfficiency {
17    /// Create new server efficiency metrics
18    pub fn new(
19        throughput_samples_per_sec: f64,
20        gpu_utilization_percent: f64,
21        memory_bandwidth_gbps: f64,
22    ) -> Self {
23        Self {
24            throughput_samples_per_sec,
25            gpu_utilization_percent: gpu_utilization_percent.clamp(0.0, 100.0),
26            memory_bandwidth_gbps,
27        }
28    }
29
30    /// Check if GPU is being efficiently utilized (>70%)
31    pub fn is_gpu_efficient(&self) -> bool {
32        self.gpu_utilization_percent >= 70.0
33    }
34
35    /// Check if GPU is underutilized (<50%)
36    pub fn is_gpu_underutilized(&self) -> bool {
37        self.gpu_utilization_percent < 50.0
38    }
39
40    /// Calculate throughput efficiency (samples per second per % GPU util)
41    pub fn throughput_efficiency(&self) -> f64 {
42        if self.gpu_utilization_percent > 0.0 {
43            self.throughput_samples_per_sec / self.gpu_utilization_percent
44        } else {
45            0.0
46        }
47    }
48
49    /// Estimate maximum throughput at 100% utilization
50    pub fn estimated_max_throughput(&self) -> f64 {
51        if self.gpu_utilization_percent > 0.0 {
52            self.throughput_samples_per_sec * (100.0 / self.gpu_utilization_percent)
53        } else {
54            0.0
55        }
56    }
57
58    /// Check if memory bandwidth might be a bottleneck
59    pub fn memory_bound(&self, expected_bandwidth_gbps: f64) -> bool {
60        self.memory_bandwidth_gbps > expected_bandwidth_gbps * 0.9
61    }
62}
63
64impl Default for ServerEfficiency {
65    fn default() -> Self {
66        Self {
67            throughput_samples_per_sec: 0.0,
68            gpu_utilization_percent: 0.0,
69            memory_bandwidth_gbps: 0.0,
70        }
71    }
72}