Skip to main content

SessionManager

Struct SessionManager 

Source
pub struct SessionManager {
    pub max_connections: usize,
    pub nb_connections: usize,
    pub can_accept: bool,
    pub slab: Slab<Rc<RefCell<dyn ProxySession>>>,
    pub max_connections_per_ip: u64,
    pub retry_after: u32,
    /* private fields */
}

Fields§

§max_connections: usize§nb_connections: usize§can_accept: bool§slab: Slab<Rc<RefCell<dyn ProxySession>>>§max_connections_per_ip: u64

Default per-(cluster, source-IP) connection limit. 0 disables the feature; cluster-level overrides take precedence at check time.

§retry_after: u32

Default Retry-After header value (seconds) for HTTP 429 responses emitted on per-(cluster, source-IP) limit hit. 0 omits the header.

Implementations§

Source§

impl SessionManager

Source

pub fn new( slab: Slab<Rc<RefCell<dyn ProxySession>>>, max_connections: usize, max_connections_per_ip: u64, retry_after: u32, ) -> Rc<RefCell<Self>>

Source

pub fn effective_max_connections_per_ip( &self, override_value: Option<u64>, ) -> u64

Resolve the effective per-(cluster, source-IP) limit. override_value is the cluster-level setting from the proto Cluster message: None inherits the global default, Some(0) is explicit “unlimited”, Some(n > 0) overrides.

Source

pub fn effective_retry_after(&self, override_value: Option<u32>) -> u32

Resolve the effective Retry-After header value. Some(0) (or the global default of 0) signals “omit the header” — caller must skip emission rather than render Retry-After: 0.

Source

pub fn cluster_ip_at_limit( &self, token: Token, cluster_id: &str, ip: &IpAddr, override_value: Option<u64>, ) -> bool

Returns true when admitting token to one more connection for (cluster, ip) would exceed the resolved limit. 0 is treated as unlimited. A token that already holds a slot for this (cluster, ip) is NEVER at the limit — H2 sessions multiplex many streams to the same cluster on a single connection, and the limit governs distinct frontend connections, not streams.

Hot-path: called for every cluster-resolving request from mux/router::connect. The nested-map storage lets both lookups borrow cluster_id and ip; no per-call allocation runs here in steady state.

Source

pub fn track_cluster_ip(&mut self, token: Token, cluster_id: String, ip: IpAddr)

Account token’s active connection against (cluster, ip). Idempotent within a token: a second call for the same (cluster, ip) is a no-op so H2 retries / multi-stream opens to the same cluster do not double-count.

Allocates a single owned String per (token, cluster) pair on first observation — entry(cluster_id.clone()) materialises a new outer-map slot. Subsequent IPs under the same (token, cluster) reuse the existing slot.

Source

pub fn untrack_all_cluster_ip(&mut self, token: Token)

Drain every (cluster, ip) slot held by token and apply the matching decrements. Called on session teardown only — there is no per-stream untrack because the limit is per-connection, not per-stream. Removes empty inner maps so the outer connections_per_cluster_ip does not retain (cluster_id, empty_map) orphans across cluster lifetimes.

Source

pub fn clear_cluster_ip_tracking(&mut self)

Wipe every per-(cluster, source-IP) accounting bucket. Called by the runtime SetMaxConnectionsPerIp(0) path so disabling the feature does not leave dead bookkeeping behind that a future re-enable would consult.

Source

pub fn at_capacity(&self) -> bool

The slab is considered at capacity if it contains more sessions than twice max_connections

Source

pub fn accept_slab_threshold(&self) -> usize

The slab fill level at which at_capacity flips to true and the accept queue is flushed. Reported as slab.accept_threshold so the per-iteration slab.accept_threshold_percent gauge in the run loop can chart proximity to this gate, distinct from raw slab usage.

The constant 10 + 2 * max_connections is the historical pre-knob budget; configured slab capacity is 10 + slab_entries_per_connection * max_connections (see command/src/config.rs) and can be larger, so slab.usage_percent (against slab.capacity()) and slab.accept_threshold_percent (against this gate) are emitted as independent gauges.

Source

pub fn check_limits(&mut self) -> bool

Check the number of connections against max_connections, and the slab capacity. Returns false if limits are reached.

Source

pub fn to_session(token: Token) -> SessionToken

Source

pub fn incr(&mut self)

Source

pub fn decr(&mut self)

Decrements the number of sessions, start accepting new connections if the capacity limit of 90% has not been reached.

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<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more