pub struct WeightedFairQueue<T> { /* private fields */ }Expand description
Weighted-fair queue, parameterized over item type T.
Maintains one virtual sub-queue per active database_id. The dispatcher
calls pop_next() to retrieve the next item following deficit round-robin
ordering. Total capacity across all virtual queues is bounded; try_enqueue
returns Err(item) when the total is full.
Implementations§
Source§impl<T> WeightedFairQueue<T>
impl<T> WeightedFairQueue<T>
Sourcepub fn new(capacity: usize, reap_after_pops: usize) -> Self
pub fn new(capacity: usize, reap_after_pops: usize) -> Self
Create a new weighted-fair queue with the given total capacity and reap
threshold. reap_after_pops controls how many empty queues persist
after draining before being garbage-collected.
Sourcepub fn try_enqueue(&mut self, database_id: u64, item: T) -> Result<(), T>
pub fn try_enqueue(&mut self, database_id: u64, item: T) -> Result<(), T>
Attempt to enqueue item for database_id. Returns Err(item) if the
total queue has reached capacity.
Sourcepub fn set_priority(&mut self, database_id: u64, cls: PriorityClass)
pub fn set_priority(&mut self, database_id: u64, cls: PriorityClass)
Set (or update) the priority class for a database. Applied on the next
pop_next call after this update.
Sourcepub fn pop_next(&mut self) -> Option<T>
pub fn pop_next(&mut self) -> Option<T>
Pop the next item using deficit round-robin across all virtual queues.
Returns None if all virtual queues are empty.
Each database is served for up to priority_weight(class) consecutive
items before the scheduler rotates to the next database. Deficit credits
are added once per turn (when a DB’s deficit reaches zero and it re-enters
the front of the rotation) and carried across calls so databases with
lower arrival rates still accumulate credits fairly.
Sourcepub fn depth_for(&self, database_id: u64) -> usize
pub fn depth_for(&self, database_id: u64) -> usize
Number of items queued for a specific database.
Sourcepub fn total_depth(&self) -> usize
pub fn total_depth(&self) -> usize
Total items across all virtual queues.
Sourcepub fn is_throttled_for(&self, database_id: u64) -> bool
pub fn is_throttled_for(&self, database_id: u64) -> bool
Returns true if the given database’s virtual queue has reached ≥ 85%
of its fair share of total capacity.
Fair share = capacity / active_databases (floor division, min 1).
Databases with higher priority class receive proportionally more fair
share in the weight sense but the slot fair share is still equal
(per-DB slot pressure uses equal division to avoid one class starving
another’s absolute headroom).
Sourcepub fn is_suspended_for(&self, database_id: u64) -> bool
pub fn is_suspended_for(&self, database_id: u64) -> bool
Returns true if the given database’s virtual queue has reached ≥ 95%
of its fair share of total capacity.
Sourcepub fn active_database_count(&self) -> usize
pub fn active_database_count(&self) -> usize
Number of active virtual queues (including empty, not-yet-reaped ones).
Auto Trait Implementations§
impl<T> Freeze for WeightedFairQueue<T>
impl<T> RefUnwindSafe for WeightedFairQueue<T>where
T: RefUnwindSafe,
impl<T> Send for WeightedFairQueue<T>where
T: Send,
impl<T> Sync for WeightedFairQueue<T>where
T: Sync,
impl<T> Unpin for WeightedFairQueue<T>where
T: Unpin,
impl<T> UnsafeUnpin for WeightedFairQueue<T>
impl<T> UnwindSafe for WeightedFairQueue<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
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
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> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.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.