cd /news/ai-infrastructure/when-linux-cgroups-quietly-throttle-… · home › topics › ai-infrastructure › article
[ARTICLE · art-181094] src=dev.to ↗ pub= topic=ai-infrastructure verified=true sentiment=· neutral

When Linux cgroups Quietly Throttle API Gateway TCP

A CDN77 debugging report, published November 25 and surfaced on Hacker News, traced intermittent nginx throughput collapse to a Linux memory-cgroup signal that pushes affected TCP sockets onto a constrained receive-window path. The slowdown appeared only on cache misses, was limited to nginx processes, recovered without intervention, and did not reproduce with a direct curl from the same host. The report points to the version-specific tcp_under_memory_pressure() branch in Linux 6.19, which checks a socket's memory cgroup and its ancestors before global TCP memory pressure, recording a MEMCG_SOCK_THROTTLED event when a pressure timestamp is still active.

recommendation

When only cache-miss gateway paths slow down, compare cached, cache-miss, direct-from-host and neighboring-gateway requests, and check cgroup v2 memory.events for sock_throttled before tuning proxy buffers.

more in playbook: Running AI in production
by read6 min views14 publishedDec 3, 2026

Originally published by Yilia Lin on API7.ai on 2026-12-01.

This republication was prepared with AI assistance. The original article’s drafting process has not been verified.

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.

sock_throttled in cgroup v2 memory.events; the counter shows that the pressure branch was used, not why reclaim became inefficient. 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.

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:

memory.high or memory.max was crossed. In the reported incident, the memory controller and service placement were enough to make the reclaim-efficiency signal relevant. 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:

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.

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:

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.

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.

── more in #ai-infrastructure 4 stories · sorted by recency
── more on @cdn77 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/when-linux-cgroups-q…] indexed:0 read:6min 2026-12-03 · —