Skip to main content

PressureMonitor

Struct PressureMonitor 

Source
pub struct PressureMonitor { /* private fields */ }
Expand description

Monitors rho = used_tokens / max_tokens and recommends compression actions. All thresholds come from ContextConfig — no hardcoded constants.

Implementations§

Source§

impl PressureMonitor

Source

pub fn new(max_tokens: u32, config: ContextConfig) -> Self

Source

pub fn max_tokens(&self) -> u32

Source

pub fn pressure( &self, partitions: &ContextPartitions, engine: &ContextTokenEngine, observed_prompt_tokens: Option<u32>, ) -> f64

Current pressure rho ∈ [0, +∞). Uses provider-reported prompt tokens when available; otherwise estimates from partitions.

This is the raw rho (full partition weight). Making rho paging-aware — i.e. subtracting non-resident (Collapsed/SpooledOut/PagedOut) handle tokens so paging immediately relieves pressure — is not a drop-in here: [crate::context::manager::ContextManager::recompute_handle_residency] decides the Resident↔Collapsed projection from this very rho, so subtracting collapsed tokens would drop rho below collapse_threshold and immediately un-collapse (oscillation). That needs a deliberate split into raw rho (drives the collapse decision) vs effective rho (drives further compaction/renewal), tracked as remaining W1-1 design work — see ContextManager::rho.

Source

pub fn recommend(&self, rho: f64) -> PressureAction

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.