Linux cgroup TCP throttling: debugging slow nginx downloads
A machine can have memory to spare, clean global network counters, and one nginx download path crawling for hours. That mismatch is the useful clue. Linux control groups (cgroups) can throttle TCP (Transmission Control Protocol) behavior for one service even while the host looks healthy, so debugging only from the host dashboard can send you toward the wrong layer. Linux cgroup TCP throttling is a useful way to frame the investigation.
CDN77’s November 25 engineering post follows this exact failure. The valuable part is not a kernel quirk to memorize. It is the investigation: compare paths, probe the TCP state, follow the call chain into memory reclaim, then add observability where the pressure actually exists.
Start with the boundary, not the presumed cause
The reported slowdown affected nginx cache-miss connections intermittently. A direct curl test on the same server worked, and rebooting cleared the condition temporarily. Those comparisons did not prove the network or nginx configuration innocent, but they narrowed the search to the service’s execution context.
That distinction matters in practice. A request served from cache and one that misses it can take different paths through the same service. Meanwhile, a shell-run transfer may not share the nginx process’s control group, memory accounting, or socket state. Reproducing the symptom from a different context can produce a reassuring result that answers the wrong question.
I would capture a small comparison matrix before changing anything:
- nginx cache hit versus cache miss,
- a transfer through nginx versus a direct
curl, - the affected service versus another process on the host,
- the same tests before and during the slowdown.
Keep these details consistent during the comparison:
- client,
- file,
- network route.
Change the execution boundary while keeping other variables steady.
How did Linux cgroup TCP throttling evade the global counters?
CDN77 used bpftrace, a tracing tool for eBPF (extended Berkeley Packet Filter) programs, to inspect the kernel’s tcp_rcv_established path. The probe showed rcv_ssthresh stuck at four times the advertised maximum segment size (MSS). That observation pointed to TCP receive behavior, beyond the simple theory of a low nginx worker count.
The source investigation then followed the kernel path through tcp_under_memory_pressure() and into cgroup socket pressure. The surprising detail was the scope: the pressure state could be set for a cgroup even though the host-wide TcpExtTCPMemoryPressures counter remained at zero. A zero in a global counter was accurate about global pressure.
It just did not answer whether this service’s cgroup was under pressure.
The report describes a reclaim shortfall across a 512-page window. With 4 KiB pages, that window is 2 MiB. In the kernel version investigated, the ratio represented reclaim efficiency rather than the amount of free RAM on the machine. The resulting cgroup socket-pressure flag could remain set for at least one second.
It is a narrow explanation tied to one kernel version; do not assume every current kernel behaves identically. Kernel code changes. Check the deployed kernel and trace the actual path before carrying this mechanism into a different incident.
Trace the state before applying a workaround
This debugging sequence applies even when the exact kernel mechanism differs:
- Confirm whether the symptom belongs to one service, one request path, or the whole host.
- Compare service-level results with host-level and global protocol counters.
- Probe the relevant runtime state while the slowdown is happening.
- Read the matching kernel source path for the deployed version.
- Reproduce the test inside the same systemd unit or container boundary.
That last step is easy to skip. A test started from an interactive shell is not necessarily a reproduction of the service’s resource policy. Check the process’s cgroup membership and the memory configuration that actually applies to it. For systemd cgroup performance work, the unit boundary is part of the experiment, rather than incidental packaging.
CDN77’s immediate workaround moved nginx into the root cgroup. In the investigated path, vmpressure() returned early there. That helped the affected setup. It does not make “remove cgroups” a sound general fix.
Cgroups provide useful resource isolation and control; bypassing them can trade one opaque performance issue for less predictable resource behavior elsewhere.
Use that workaround only after confirming the same path and kernel behavior on your own system. If the evidence does not match, it is not the same diagnosis.
Put observability at the level where pressure occurs
The report says the investigation contributed a sock_throttled counter to memory.events in Linux 6.19. That is the operational lesson I want to keep: telemetry should match the boundary where the failure is happening. Host dashboards and global TCP counters remain useful, but they cannot replace service- or cgroup-level evidence when the condition is scoped there.
For a Linux service under systemd or a container runtime, I would alert on a change in the relevant cgroup’s memory events alongside throughput and latency for that service. Keep the series labeled by unit or cgroup so an aggregate cannot flatten the signal. Also record the kernel version in the incident notes; a counter name or code path can move across releases.
A practical incident checklist is short:
- Save the affected unit’s cgroup and memory-event readings during the slowdown.
- Compare them with the host’s global memory and TCP counters.
- Record the deployed kernel release and the service’s cgroup limits.
- Run the same request through the same service boundary while tracing.
- Verify any workaround against that kernel before rolling it out broadly.
The checklist will not diagnose every throughput regression. It does keep “the host is fine” from becoming the end of the investigation when one cgroup is telling a different story.
FAQ
Does zero TcpExtTCPMemoryPressures rule out TCP memory pressure?
No. In CDN77’s report, cgroup socket pressure was present while that global counter stayed at zero. Check cgroup-level state as well as host-wide counters.
Should I move a slow service into the root cgroup?
Only if tracing confirms the same vmpressure() behavior on the deployed kernel. The article’s workaround describes its investigated setup, not a universal tuning recommendation.
Is the 512-page reclaim window a constant across Linux kernels?
Treat it as the behavior described for the kernel version in the report. Validate the code path and page size on your deployed version before using the 2 MiB figure to explain another incident.