pub struct LoadBalancer { /* private fields */ }Expand description
Load balancer for tensor distribution
Implementations§
Source§impl LoadBalancer
impl LoadBalancer
Sourcepub fn new(cluster: Arc<ClusterState>, config: LoadBalanceConfig) -> Self
pub fn new(cluster: Arc<ClusterState>, config: LoadBalanceConfig) -> Self
Create new load balancer
Sourcepub fn with_runtime_profile(
cluster: Arc<ClusterState>,
profile: &RuntimeProfile,
) -> Self
pub fn with_runtime_profile( cluster: Arc<ClusterState>, profile: &RuntimeProfile, ) -> Self
Create a load balancer with configuration derived from the local runtime profile.
Sourcepub fn config(&self) -> LoadBalanceConfig
pub fn config(&self) -> LoadBalanceConfig
Access the current configuration.
Sourcepub fn distribute_layers(
&self,
layers: &[LayerSpec],
) -> Result<LoadDistributionPlan, String>
pub fn distribute_layers( &self, layers: &[LayerSpec], ) -> Result<LoadDistributionPlan, String>
Distribute tensor layers across nodes based on VRAM capacity.
Optimized using cursor-based index traversal instead of costly vector draining and shifting elements, improving complexity from O(N^2) to O(N). Further optimized by sorting references to NodeResources instead of cloning them, and dynamically avoiding layer cloning/sorting if they are already in sequential order.
Sourcepub fn distribute_layers_with_runtime_profile(
&self,
layers: &[LayerSpec],
profile: &RuntimeProfile,
) -> Result<LoadDistributionPlan, String>
pub fn distribute_layers_with_runtime_profile( &self, layers: &[LayerSpec], profile: &RuntimeProfile, ) -> Result<LoadDistributionPlan, String>
Distribute layers and directly chunk large node allocations to match worker parallelism.
OPTIMIZATION: Delegates directly to distribute_layers_internal with Some(max_layers_per_slice)
to generate chunked tensor slices in a single pass during greedy assignment. This completely
eliminates intermediate single-slice vector allocations (vec![slice]), avoids intermediate
LoadDistributionPlan construction, and bypasses multi-pass post-processing traversals.
Sourcepub fn shed_load(&self) -> Vec<(String, String)>
pub fn shed_load(&self) -> Vec<(String, String)>
Shed load from overloaded nodes to underloaded ones.
OPTIMIZATION: Collects overloaded and underloaded node candidates in a single-pass loop
over cluster metrics under lock, completely eliminating intermediate active_nodes vector
allocations and inlining best target lookup.
Sourcepub fn reconfigure_from_system_profile(&self, profile: &SystemProfile)
pub fn reconfigure_from_system_profile(&self, profile: &SystemProfile)
Re-tune load-balancing thresholds from a system profile detected at runtime.
Sourcepub fn subscribe_to_watcher(
self: &Arc<Self>,
watcher: &SystemProfileWatcher,
) -> JoinHandle<()> ⓘ
pub fn subscribe_to_watcher( self: &Arc<Self>, watcher: &SystemProfileWatcher, ) -> JoinHandle<()> ⓘ
Subscribe to a SystemProfileWatcher’s broadcast channel and
automatically re-tune whenever hardware changes are detected.
Returns a JoinHandle that can be cancelled by dropping it.
Sourcepub fn distribute_with_deadlock_prevention(
&self,
layers: &[LayerSpec],
) -> Result<LoadDistributionPlan, String>
pub fn distribute_with_deadlock_prevention( &self, layers: &[LayerSpec], ) -> Result<LoadDistributionPlan, String>
Distribute layers with deadlock prevention
Trait Implementations§
Source§impl Clone for LoadBalancer
impl Clone for LoadBalancer
Auto Trait Implementations§
impl Freeze for LoadBalancer
impl RefUnwindSafe for LoadBalancer
impl Send for LoadBalancer
impl Sync for LoadBalancer
impl Unpin for LoadBalancer
impl UnsafeUnpin for LoadBalancer
impl UnwindSafe for LoadBalancer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more