Expand description
Request admission control: bounded parse concurrency + a byte-weighted memory budget + a coarse RSS circuit breaker.
Every parse handler acquires an AdmissionGuard BEFORE buffering the
upload. Without this, N concurrent large uploads each buffer the full file
and spawn blocking decode/mesh work whose working set is a multiple of the
file size; nothing bounds N, so the container is OOM-killed (a full outage
on the single-replica deployment). The byte-weighted semaphore is the
load-bearing bound: total admitted upload bytes can never exceed the
configured budget. The CPU semaphore keeps the blocking pool from
thrashing, and the RSS breaker sheds load before the kernel does.
Explicit semaphores were chosen over tower::limit::GlobalConcurrencyLimit:
the tower layer makes over-limit requests wait unboundedly with no 503/
Retry-After, wraps cheap GET routes too, and cannot express a byte budget.
Structs§
- Admission
- Shared admission state (one per process, in
AppState). - Admission
Cfg - Tuning knobs, derived from
crate::config::Configat startup. - Admission
Guard - RAII permit pair; drops release the slots.
Constants§
- BYTES_
PER_ 🔒PERMIT - One memory-budget permit spans this many upload bytes, so the semaphore’s
permit count stays far below
Semaphore::MAX_PERMITSeven for multi-GB budgets.
Functions§
- resident_
bytes_ now - Resident set size of this process in bytes, or 0 when unknown.
- spawn_
rss_ sampler - Background sampler: refreshes the shared RSS gauge every 500 ms so the admission breaker reads a cheap atomic, never the filesystem, per request.