pub struct LoadBalancer { /* private fields */ }Expand description
Load balancer for distributing work across GPUs
Implementations§
Source§impl LoadBalancer
impl LoadBalancer
Sourcepub fn new(devices: Vec<Arc<GpuDevice>>, strategy: SelectionStrategy) -> Self
pub fn new(devices: Vec<Arc<GpuDevice>>, strategy: SelectionStrategy) -> Self
Create a new load balancer
Sourcepub fn migration_config(&self) -> MigrationConfig
pub fn migration_config(&self) -> MigrationConfig
Get the migration configuration
Sourcepub fn set_migration_config(&self, config: MigrationConfig)
pub fn set_migration_config(&self, config: MigrationConfig)
Update migration configuration
Sourcepub fn select_device(&self) -> Result<Arc<GpuDevice>>
pub fn select_device(&self) -> Result<Arc<GpuDevice>>
Select a device using the configured strategy
Sourcepub fn select_weighted(&self) -> Result<Arc<GpuDevice>>
pub fn select_weighted(&self) -> Result<Arc<GpuDevice>>
Select device using weighted strategy based on device performance
Sourcepub fn get_device_loads(&self) -> Vec<DeviceLoad>
pub fn get_device_loads(&self) -> Vec<DeviceLoad>
Get current load information for all devices
Sourcepub fn identify_overloaded_devices(&self) -> Vec<DeviceLoad>
pub fn identify_overloaded_devices(&self) -> Vec<DeviceLoad>
Identify overloaded devices
Sourcepub fn identify_underutilized_devices(&self) -> Vec<DeviceLoad>
pub fn identify_underutilized_devices(&self) -> Vec<DeviceLoad>
Identify underutilized devices
Sourcepub fn is_imbalanced(&self) -> bool
pub fn is_imbalanced(&self) -> bool
Check if load is imbalanced (requires rebalancing)
Sourcepub fn calculate_transfer_cost(
&self,
source_device: usize,
target_device: usize,
data_size: u64,
) -> Result<f64>
pub fn calculate_transfer_cost( &self, source_device: usize, target_device: usize, data_size: u64, ) -> Result<f64>
Calculate data transfer cost between two devices
Sourcepub fn create_migration_plan(
&self,
workload: MigratableWorkload,
target_device: usize,
) -> Result<MigrationPlan>
pub fn create_migration_plan( &self, workload: MigratableWorkload, target_device: usize, ) -> Result<MigrationPlan>
Create a migration plan for a workload
Sourcepub fn find_migration_target(
&self,
source_device: usize,
) -> Result<Option<usize>>
pub fn find_migration_target( &self, source_device: usize, ) -> Result<Option<usize>>
Find best migration target for an overloaded device
Sourcepub fn select_workload_for_migration(
&self,
source_device: usize,
) -> Option<MigratableWorkload>
pub fn select_workload_for_migration( &self, source_device: usize, ) -> Option<MigratableWorkload>
Select workload to migrate from an overloaded device
Sourcepub fn execute_migration(&self, plan: &MigrationPlan) -> Result<MigrationResult>
pub fn execute_migration(&self, plan: &MigrationPlan) -> Result<MigrationResult>
Execute a migration (simulated - actual data transfer would use sync module)
Sourcepub fn rebalance(&self) -> Result<Vec<MigrationResult>>
pub fn rebalance(&self) -> Result<Vec<MigrationResult>>
Rebalance workloads across devices
This method implements the core workload migration logic:
- Monitor GPU utilization across all devices
- Identify overloaded and underutilized GPUs
- Calculate transfer costs for potential migrations
- Execute migrations that improve overall balance
Sourcepub fn register_workload(
&self,
device_index: usize,
memory_size: u64,
compute_intensity: f32,
priority: u32,
) -> Result<u64>
pub fn register_workload( &self, device_index: usize, memory_size: u64, compute_intensity: f32, priority: u32, ) -> Result<u64>
Register a new workload on a device
Sourcepub fn unregister_workload(
&self,
device_index: usize,
workload_id: u64,
) -> Result<()>
pub fn unregister_workload( &self, device_index: usize, workload_id: u64, ) -> Result<()>
Unregister a workload (completed or cancelled)
Sourcepub fn task_started(&self, device_index: usize)
pub fn task_started(&self, device_index: usize)
Mark task started on device
Sourcepub fn task_completed(&self, device_index: usize, duration_us: u64)
pub fn task_completed(&self, device_index: usize, duration_us: u64)
Mark task completed on device
Sourcepub fn print_stats(&self)
pub fn print_stats(&self)
Print load statistics
Sourcepub fn reset_stats(&self)
pub fn reset_stats(&self)
Reset statistics
Sourcepub fn get_device_utilization(&self, device_index: usize) -> f32
pub fn get_device_utilization(&self, device_index: usize) -> f32
Get device utilization (0.0 to 1.0)
Sourcepub fn get_cluster_utilization(&self) -> f32
pub fn get_cluster_utilization(&self) -> f32
Get overall cluster utilization (0.0 to 1.0)
Sourcepub fn suggest_device(&self, estimated_memory: u64) -> Result<Arc<GpuDevice>>
pub fn suggest_device(&self, estimated_memory: u64) -> Result<Arc<GpuDevice>>
Suggest optimal device for next task
Sourcepub fn get_migration_stats(&self) -> (usize, usize, f64)
pub fn get_migration_stats(&self) -> (usize, usize, f64)
Get migration history statistics
Sourcepub fn device_count(&self) -> usize
pub fn device_count(&self) -> usize
Get device count