When static queue limits cause goodput collapse under overload, use CoDel sojourn shedding with per-tenant FQ-CoDel queues.
TL;DR30-second simplified summary▾
By tracking dequeue_ts - enqueue_ts over 100 ms intervals and ramping drops at interval / sqrt(N), CoDel absorbs short bursts while shedding standing overload automatically.
L = lambda * W: a queue of 1,000 items takes 100 ms when draining at 10,000 req/s, but 10 seconds when downstream slows to 100 req/s.enqueue_ts and dequeue_ts must use a monotonic clock (CLOCK_MONOTONIC) rather than wall-clock time.P · Problem & Why Static Queue Depth Collapses Goodput.
Suppose your service has a 1,000-slot FIFO queue and a 500 ms client timeout. Normally it processes 5,000 req/s, so a full queue drains in 200 ms.
Now a slow database query drops throughput to 500 req/s. A full 1,000-slot queue now takes 2,000 ms to drain! Every single request sits in the queue for 2 seconds, times out on the client after 500 ms, and gets retried—yet workers still execute all 1,000 dead requests, dropping useful goodput to 0%.
Static FIFO Depth (2,000 ms Stale Queue) vs. CoDel Sojourn (<10 ms)
- Measures item count, not wait time
- Standing queue hits 2,000 ms
- 0% goodput on dead retries
- Measures dequeue_ts - enqueue_ts
- 5 ms target / 100 ms window
- Sheds stale items; keeps ~100% goodput
R · Representation: Sojourn Time, Target & Interval.
CoDel attaches a monotonic enqueue_ts to every queued request. On dequeue, it computes sojourn = now - enqueue_ts.
A short traffic burst might push sojourn to 30 ms for 20 ms, then drain back to 0 ms—that's healthy buffering, so CoDel does NOT drop! Only if sojourn stays above target (5 ms) continuously for an entire interval (100 ms) does CoDel classify the queue as a standing bottleneck.
Enqueue Timestamp -> Dequeue Sojourn Check -> Drop or Serve
I · Invariant: 1 / sqrt(N) Drop Cadence & Head-Drop.
Once CoDel enters dropping mode, it shouldn't drop every single request at once (which would cause wild oscillation), nor drop too slowly.
CoDel schedules the next drop at next_drop = now + interval / sqrt(drop_count). Drop #1 waits 100 ms, Drop #2 waits 70.7 ms, Drop #4 waits 50 ms, smoothly ramping shedding rate to match the overload slope until sojourn < target.
Healthy -> Above Target (100 ms) -> Dropping (1/sqrt(N)) -> Recovered
M · Mechanics at Scale: FQ-CoDel & Tenant Isolation.
If all tenants share a single CoDel queue, one tenant flooding 100K RPS pushes sojourn time above 5 ms and causes CoDel to drop innocent tenants' requests.
FQ-CoDel (Fair Queueing + CoDel) hashes requests by tenant_id (or priority class) into separate virtual queues scheduled via Deficit Round-Robin (DRR), running CoDel independently per queue.
Tenant Hash -> Per-Tenant CoDel Queues -> DRR Scheduler -> Workers
- Problem
- How to shed overload without tuning brittle queue-depth constants or hurting innocent tenants.
- Naive Solution
- Use a single shared FIFO queue with a fixed
max_size = 1000. - Why It Fails
- Fixed depth cannot adapt when downstream throughput drops, and a single queue lets one noisy tenant starve everyone.
- Alternatives
- Static FIFO tail-drop vs. Single CoDel vs. FQ-CoDel (per-tenant/priority Deficit Round-Robin + CoDel).
- Engineering Decision
- Use CoDel sojourn-time shedding paired with per-tenant/priority queues (FQ-CoDel) and explicit
503 + Retry-Afterresponses. - Trade-Offs
- Requires slightly more memory for per-tenant/priority buckets in exchange for automatic adaptation and noisy-neighbor isolation.
E · Edge Cases, Assumptions & When NOT to Use CoDel.
CoDel assumes requests are short-lived RPCs where waiting in a queue longer than target (5 ms) signals overload.
When NOT to use CoDel: (1) Long-running offline batch/ETL queues (e.g., Spark/Celery jobs meant to wait minutes in a backlog) should use backpressure or autoscaling, not 5 ms CoDel drops; (2) If clients immediately retry 503 without exponential backoff + jitter, shedding only shifts load to retry parsing.
Low-Latency RPC (CoDel) vs. Batch Backlog (Autoscaled Queue)
A background video-transcoding job queue intentionally buffers jobs for 2–5 minutes during traffic spikes. An engineer enables default CoDel (target = 5 ms, interval = 100 ms) on that queue. What happens?
Practice: Make the trade-off yourself.
Why does CoDel measure queue sojourn time (`dequeue_ts - enqueue_ts`) instead of queue item count?