hyperlane-plugin-concurrency 23.1.0

A lock-free atomic global and per-route-prefix in-flight concurrency limiter and adaptive load-shedding plugin for the Hyperlane framework with optional bounded Tokio Semaphore queuing, leak-proof RAII Context permits, and prebuilt 503 Retry-After wire responses.
Documentation
/// Context attribute key storing the active RAII [`ConcurrencyPermit`](crate::ConcurrencyPermit).
pub const ATTR_CONCURRENCY_PERMIT: &str = "hyperlane_plugin_concurrency_permit";

/// Default global maximum concurrent in-flight requests.
pub const DEFAULT_MAX_IN_FLIGHT: usize = 1_024;

/// Default `Retry-After` header value in seconds emitted on `503 Service Unavailable`.
pub const DEFAULT_RETRY_AFTER_SECS: u64 = 1;

/// Default rejection body emitted when concurrency capacity is saturated.
pub const DEFAULT_SHED_BODY: &[u8] = b"Service Unavailable";

/// Default `Content-Type` header emitted on shed responses.
pub const DEFAULT_SHED_CONTENT_TYPE: &str = "text/plain; charset=utf-8";

/// Default target request latency in milliseconds for AIMD adaptive load shedding.
pub const DEFAULT_ADAPTIVE_TARGET_LATENCY_MS: u64 = 100;

/// Default EWMA smoothing denominator (alpha = 1 / 8).
pub(crate) const EWMA_SHIFT: u32 = 3;

/// Microseconds per millisecond conversion factor.
pub(crate) const MICROS_PER_MS: u64 = 1_000;

/// Microseconds per second conversion factor for fast 64-bit elapsed latency calculation.
pub(crate) const MICROS_PER_SECOND: u64 = 1_000_000;

/// Threshold above which exact exempt-path checks switch from linear slice scan to hash set.
pub(crate) const EXEMPT_SET_THRESHOLD: usize = 4;

/// Sentinel stored in compact `u32` permit slots when no prefix concurrency rule matched.
pub(crate) const NO_PREFIX_SLOT: u32 = u32::MAX;

/// ASCII forward-slash byte (`/`).
pub(crate) const ASCII_SLASH: u8 = b'/';