When Linux cgroups Quietly Throttle API Gateway TCP
December 1, 2026
An API gateway can have healthy CPU, free memory, clean logs, and a responsive origin while a subset of upstream transfers slows dramatically. That combination tempts teams to tune proxy buffers or blame the network. A recent Linux investigation showed why the evidence can point lower in the stack.
On November 25, CDN77 published a debugging report about intermittent nginx throughput collapse. The report reached the Hacker News front page because its symptoms were unusually deceptive: the slowdown affected nginx processes, appeared on cache misses, recovered without intervention, and did not reproduce with a direct curl from the same host. The cause was a Linux memory-cgroup signal that put affected TCP sockets on a constrained receive-window path.
The operational lesson is not that every slow API is a kernel bug. It is that gateway diagnosis must preserve the boundary between application latency, proxy behavior, TCP state, and cgroup accounting.
Key Takeaways
- A successful health check and low host memory use do not rule out socket behavior scoped to one service cgroup.
- Compare cache hits, cache misses, direct-origin requests, and gateway requests before changing proxy configuration.
- Linux 6.19 exposes
sock_throttledin cgroup v2memory.events; the counter shows that the pressure branch was used, not why reclaim became inefficient. - Apache APISIX latency metrics help identify the slow hop, but they do not prove a kernel-level cause.
- Moving a service to the root cgroup may change the symptom while also changing accounting and isolation. Treat it as a controlled diagnostic experiment, not a general fix.
Start with the Failure Shape
CDN77's incident had four useful discriminators. The behavior was intermittent, connection-specific, limited to nginx, and visible when nginx fetched data on a cache miss. A direct transfer from the affected server was fast. Static configuration and neighboring servers looked alike, while CPU, host memory, and kernel logs did not explain the difference.
That shape narrows the search more effectively than a generic “gateway is slow” alert. Build a small comparison matrix before tuning anything:
| Test | What it isolates | Interpretation limit |
|---|---|---|
| Cached response through gateway | Client-to-gateway path and local response delivery | Does not exercise the origin connection |
| Cache miss through gateway | Full client → gateway → origin path | Still combines proxy and kernel behavior |
| Direct request from gateway host to origin | Host network path without the gateway worker | Uses a different process and socket cgroup |
| Same route on a neighboring gateway | Workload and origin with another data plane | Kernel, placement, and connection state can differ |
If only the cache-miss gateway path is slow, keep origin fetch, worker process, socket state, and service cgroup in scope. If the direct request is also slow, the proxy-specific hypothesis weakens. If cached responses degrade too, the bottleneck may be downstream or local rather than origin-facing.
This is the same path discipline required for HTTP connection-reuse diagnosis, but the mechanism here is different. Connection reuse concerns whether a socket returns to a pool. Cgroup socket pressure can constrain an established connection that is otherwise functioning.
What the Linux 6.19 Path Actually Does
The relevant branch is version-specific. In Linux 6.19, tcp_under_memory_pressure() first checks whether the socket's memory cgroup is under pressure and only then checks global TCP memory pressure. The cgroup helper walks the socket's cgroup and its ancestors. When a pressure timestamp is still active, that helper records a MEMCG_SOCK_THROTTLED event and returns true.
The signal comes from reclaim efficiency, not a direct comparison with total free host memory. Linux 6.19's vmpressure.c uses a window of 512 scanned pages, documented there as 2 MiB when pages are 4 KiB. A medium pressure level begins when unsuccessful reclaim reaches 60 percent—equivalently, when less than 40 percent of the scanned pages were reclaimed. For the cgroup v2 socket-pressure path, the kernel asserts the pressure state for one second; later events can extend it.
When TCP receive processing sees that state, it can take the pressure branch instead of growing the receive window normally. CDN77 observed a very small rcv_ssthresh and traced the path through tcp_adjust_rcv_ssthresh(). Because the pressure flag is cgroup-scoped, connections whose sockets are charged to that cgroup or a pressured ancestor can encounter the same branch.
Two qualifications belong beside that explanation:
- The mechanism does not prove that a configured
memory.highormemory.maxwas crossed. In the reported incident, loading the memory controller and service placement were enough to make the reclaim-efficiency signal relevant. - Seeing the branch does not identify the workload that caused reclaim or establish that this is the only contributor to latency. Page-cache behavior, socket placement, and the exact kernel build still need investigation.
Use Gateway Metrics to Locate, Not Invent, the Cause
Apache APISIX 3.21's Prometheus plugin exposes apisix_http_latency with request, upstream, and apisix types. The upstream series measures time waiting on the upstream response. The apisix value is the request latency minus upstream latency and includes downstream traffic time plus NGINX-side time; it is not a pure Lua execution metric.
Those definitions make the metric useful for phase separation:
- Higher upstream latency on cache misses points toward the gateway-to-origin phase, but not specifically to TCP receive-window pressure.
- Higher request latency with stable upstream latency shifts attention toward downstream delivery or local processing.
- A route or node label can help identify whether the symptom follows one data-plane instance.
Add transport evidence before declaring a kernel cause. Compare bytes per second, retransmissions, receive-window evolution, connection age, and origin timing for affected and unaffected sockets. Confirm which cgroup owns the nginx or APISIX worker. A packet capture can show window behavior, while a bounded bpftrace or eBPF probe in a test or incident window can observe the kernel branch. Apply production probes only with an owner, a time limit, and measured overhead.
On Linux 6.19, inspect the service's cgroup v2 files:
cat /sys/fs/cgroup/system.slice/apisix.service/memory.events.local cat /sys/fs/cgroup/system.slice/apisix.service/memory.stat cat /sys/fs/cgroup/system.slice/apisix.service/memory.pressure
The cgroup v2 documentation defines sock_throttled as the number of times sockets associated with the cgroup are throttled. Use memory.events.local when you want events at that cgroup rather than the hierarchical totals in memory.events. Record a baseline and compare the counter delta with the exact incident window. A nonzero lifetime total is not proof that the current request was affected.
Older kernels may not expose this counter even when related pressure logic exists. In that case, do not convert “counter unavailable” into “mechanism absent.” Pin the running kernel and distribution patches, then use version-appropriate source, tracing, and vendor guidance.
Mitigate Without Trading Away the Boundary
CDN77 temporarily moved nginx into the root cgroup because the investigated vmpressure() path returns for the root cgroup. That experiment removed the symptom in their environment, but it also changed memory accounting and out-of-memory behavior. Copying it blindly can reduce containment or move resource pressure elsewhere.
Use a staged response instead:
- Capture the failing and healthy path before changing placement.
- Confirm the running kernel, cgroup mode, service cgroup, and counter behavior.
- Reproduce with a bounded workload if possible, including cache-hit and cache-miss cases.
- Test one change at a time: kernel build, service placement, memory policy, or workload behavior.
- Verify throughput, tail latency, memory pressure, socket counts, and OOM behavior together.
- Roll out to a canary data plane and retain a fast rollback path.
Linux 6.19's new counter improves observability; CDN77 explicitly said a proper fix would follow. Do not describe the counter itself as remediation. Likewise, increasing proxy buffers or upstream keep-alive limits without evidence can add memory or socket pressure while leaving the kernel path unchanged.
Conclusion
Hidden TCP throttling is a reminder that API latency is a path, not a single dashboard panel. Start with the failure shape, compare gateway and direct paths, separate upstream from downstream latency, and then join gateway evidence with socket and cgroup state.
Apache APISIX and API7 Gateway provide a useful observation boundary for route, node, status, and latency data. They do not replace kernel diagnosis, but they help identify which traffic phase deserves it. For a broader monitoring model, use the API observability guide, then add the Linux 6.19 cgroup evidence when the symptom matches this specific failure path.



