use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ServerEfficiency {
pub throughput_samples_per_sec: f64,
pub gpu_utilization_percent: f64,
pub memory_bandwidth_gbps: f64,
}
impl ServerEfficiency {
pub fn new(
throughput_samples_per_sec: f64,
gpu_utilization_percent: f64,
memory_bandwidth_gbps: f64,
) -> Self {
Self {
throughput_samples_per_sec,
gpu_utilization_percent: gpu_utilization_percent.clamp(0.0, 100.0),
memory_bandwidth_gbps,
}
}
pub fn is_gpu_efficient(&self) -> bool {
self.gpu_utilization_percent >= 70.0
}
pub fn is_gpu_underutilized(&self) -> bool {
self.gpu_utilization_percent < 50.0
}
pub fn throughput_efficiency(&self) -> f64 {
if self.gpu_utilization_percent > 0.0 {
self.throughput_samples_per_sec / self.gpu_utilization_percent
} else {
0.0
}
}
pub fn estimated_max_throughput(&self) -> f64 {
if self.gpu_utilization_percent > 0.0 {
self.throughput_samples_per_sec * (100.0 / self.gpu_utilization_percent)
} else {
0.0
}
}
pub fn memory_bound(&self, expected_bandwidth_gbps: f64) -> bool {
self.memory_bandwidth_gbps > expected_bandwidth_gbps * 0.9
}
}
impl Default for ServerEfficiency {
fn default() -> Self {
Self {
throughput_samples_per_sec: 0.0,
gpu_utilization_percent: 0.0,
memory_bandwidth_gbps: 0.0,
}
}
}