pub struct ResourceManager { /* private fields */ }Expand description
Resource manager for streaming optimization
Implementations§
Source§impl ResourceManager
impl ResourceManager
Sourcepub fn new(config: &StreamingConfig) -> Result<Self, String>
pub fn new(config: &StreamingConfig) -> Result<Self, String>
Creates a new resource manager
Sourcepub fn start_monitoring(&mut self) -> Result<(), String>
pub fn start_monitoring(&mut self) -> Result<(), String>
Starts resource monitoring.
R4: the previous loop had no way to stop, so the thread outlived the
manager. It now polls a shutdown flag on a short tick (independent of
monitoring_frequency, which may be minutes) and
Self::stop_monitoring joins it.
Sourcepub fn stop_monitoring(&mut self) -> Result<(), String>
pub fn stop_monitoring(&mut self) -> Result<(), String>
Signals the monitoring thread to stop and waits for it.
Sourcepub fn is_monitoring(&self) -> bool
pub fn is_monitoring(&self) -> bool
Whether the background monitor is running.
Sourcepub fn collect_resource_usage(&self) -> ResourceUsage
pub fn collect_resource_usage(&self) -> ResourceUsage
Collects current resource usage from the long-lived probe.
Sourcepub fn allocate_resources(
&mut self,
component_name: &str,
memory_mb: usize,
cpu_percent: f64,
priority: ResourcePriority,
) -> Result<(), String>
pub fn allocate_resources( &mut self, component_name: &str, memory_mb: usize, cpu_percent: f64, priority: ResourcePriority, ) -> Result<(), String>
Allocates resources for a component
Sourcepub fn budget_violations(&self) -> u64
pub fn budget_violations(&self) -> u64
Number of budget violations observed so far (R7).
Sourcepub fn budget_penalty(&self) -> f64
pub fn budget_penalty(&self) -> f64
Accumulated budget-violation penalty (CF1:
ResourceBudgetConstraints::violation_penalty).
Sourcepub fn update_utilization(&mut self) -> Result<(), String>
pub fn update_utilization(&mut self) -> Result<(), String>
Updates resource utilization tracking.
When no monitoring thread is running this collects a sample itself
(throttled to monitoring_frequency). Previously start_monitoring
was never called from anywhere, so current_usage stayed at its
all-zero Default forever and every consumer of it read zeros.
Sourcepub fn has_sufficient_resources_for_processing(&self) -> Result<bool, String>
pub fn has_sufficient_resources_for_processing(&self) -> Result<bool, String>
Checks if sufficient resources are available for processing.
The CPU term is only applied when a real CPU measurement exists; before
the probe has two refreshes to compare, the placeholder 0.0 must not
be mistaken for “idle”.
Sourcepub fn compute_allocation_adaptation(
&mut self,
) -> Result<Option<Adaptation<f32>>, String>
pub fn compute_allocation_adaptation( &mut self, ) -> Result<Option<Adaptation<f32>>, String>
Computes resource allocation adaptation
Sourcepub fn predict_usage(&self) -> Option<ResourceUsage>
pub fn predict_usage(&self) -> Option<ResourceUsage>
Predicted resource usage prediction_horizon samples ahead, or None
when prediction is disabled or there is not enough history (R7).
Sourcepub fn prediction_accuracy(&self) -> &HashMap<String, f64>
pub fn prediction_accuracy(&self) -> &HashMap<String, f64>
Mean absolute percentage error of the predictor, per resource (R7).
Sourcepub fn trend_analysis(&self) -> &ResourceTrendAnalysis
pub fn trend_analysis(&self) -> &ResourceTrendAnalysis
Current resource trend analysis.
Sourcepub fn register_alert_handler(&mut self, handler: Box<dyn AlertHandler>)
pub fn register_alert_handler(&mut self, handler: Box<dyn AlertHandler>)
Registers a handler invoked for every raised alert.
Sourcepub fn active_alerts(&self) -> Vec<ResourceAlert>
pub fn active_alerts(&self) -> Vec<ResourceAlert>
Currently unresolved alerts.
Sourcepub fn alert_history(&self) -> Vec<ResourceAlert>
pub fn alert_history(&self) -> Vec<ResourceAlert>
Resolved alerts, oldest first.
Sourcepub fn apply_allocation_adaptation(
&mut self,
adaptation: &Adaptation<f32>,
) -> Result<(), String>
pub fn apply_allocation_adaptation( &mut self, adaptation: &Adaptation<f32>, ) -> Result<(), String>
Applies resource allocation adaptation
Sourcepub fn current_usage(&self) -> Result<ResourceUsage, String>
pub fn current_usage(&self) -> Result<ResourceUsage, String>
Gets current resource usage
Sourcepub fn get_usage_history(&self, count: usize) -> Vec<ResourceUsage>
pub fn get_usage_history(&self, count: usize) -> Vec<ResourceUsage>
Gets resource usage history
Sourcepub fn get_diagnostics(&self) -> ResourceDiagnostics
pub fn get_diagnostics(&self) -> ResourceDiagnostics
Gets diagnostic information
Trait Implementations§
Source§impl Drop for ResourceManager
impl Drop for ResourceManager
Auto Trait Implementations§
impl !RefUnwindSafe for ResourceManager
impl !UnwindSafe for ResourceManager
impl Freeze for ResourceManager
impl Send for ResourceManager
impl Sync for ResourceManager
impl Unpin for ResourceManager
impl UnsafeUnpin for ResourceManager
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> 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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.