---
title: "When Linux cgroups Quietly Throttle API Gateway TCP - API7.ai"
description: "Diagnose intermittent API gateway throughput collapse by separating proxy, origin, TCP, and cgroup evidence, including Linux 6.19's sock_throttled counter."
url: "https://api7.ai/blog/linux-cgroup-tcp-throttling-api-gateway"
---

[Blog](https://api7.ai/blog)

[Products](https://api7.ai/category/products)[Technology](https://api7.ai/category/technology)[Ecosystem](https://api7.ai/category/ecosystem)[Case Study](https://api7.ai/category/usercase)[Team & Community](https://api7.ai/category/community)

Search

⌘ + K

[Blog](https://api7.ai/blog)

Technology

# When Linux cgroups Quietly Throttle API Gateway TCP

[![Yilia Lin](https://github.com/Yilialinn.png)](https://github.com/Yilialinn)

[Yilia Lin](https://github.com/Yilialinn)

December 1, 2026

[Technology](https://api7.ai/category/technology)

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](https://www.cdn77.com/blog/debugging-nginx-linux-contribution). The report reached the [Hacker News front page](https://news.ycombinator.com/item?id=50699391) 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_throttled` in cgroup v2 `memory.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](https://api7.ai/blog/http-connection-reuse-api-gateway-latency), 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()`](https://github.com/torvalds/linux/blob/v6.19/include/net/tcp.h#L299-L311) 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`](https://github.com/torvalds/linux/blob/v6.19/mm/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:

1. The mechanism does not prove that a configured `memory.high` or `memory.max` was crossed. In the reported incident, loading the memory controller and service placement were enough to make the reclaim-efficiency signal relevant.
2. 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](https://apisix.apache.org/docs/apisix/3.21/plugins/prometheus/) 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](https://github.com/torvalds/linux/blob/v6.19/Documentation/admin-guide/cgroup-v2.rst#memory-interface-files) 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:

1. Capture the failing and healthy path before changing placement.
2. Confirm the running kernel, cgroup mode, service cgroup, and counter behavior.
3. Reproduce with a bounded workload if possible, including cache-hit and cache-miss cases.
4. Test one change at a time: kernel build, service placement, memory policy, or workload behavior.
5. Verify throughput, tail latency, memory pressure, socket counts, and OOM behavior together.
6. 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](https://api7.ai/blog/api-observability-guide), then add the Linux 6.19 cgroup evidence when the symptom matches this specific failure path.

Tags:

[API Gateway](https://api7.ai/tags/api-gateway)

[Linux](https://api7.ai/tags/linux)

[Performance](https://api7.ai/tags/performance)

[Observability](https://api7.ai/tags/observability)

[Apache APISIX](https://api7.ai/tags/apache-apisix)

Share article link

Share

Related Posts

[![Partial API Outages Need Retry Budgets, Not Retry Storms](https://static.api7.ai/uploads/2026/11/10/Upkbmn88_api-retry-budgets-partial-outages.webp)](https://api7.ai/blog/api-retry-budgets-partial-outages)

## [Partial API Outages Need Retry Budgets, Not Retry Storms](https://api7.ai/blog/api-retry-budgets-partial-outages)

[![Incremental API Gateway Configuration: Rebuild Less, Verify More](https://static.api7.ai/uploads/2026/11/03/5tHRA5Tn_incremental-api-gateway-configuration.webp)](https://api7.ai/blog/incremental-api-gateway-configuration)

## [Incremental API Gateway Configuration: Rebuild Less, Verify More](https://api7.ai/blog/incremental-api-gateway-configuration)

Table of Contents

- [Key Takeaways](#key-takeaways)
- [Start with the Failure Shape](#start-with-the-failure-shape)
- [What the Linux 6.19 Path Actually Does](#what-the-linux-619-path-actually-does)
- [Use Gateway Metrics to Locate, Not Invent, the Cause](#use-gateway-metrics-to-locate-not-invent-the-cause)
- [Mitigate Without Trading Away the Boundary](#mitigate-without-trading-away-the-boundary)
- [Conclusion](#conclusion)

## Related Posts

[![HTTP Connection Reuse: The Hidden API Latency Multiplier](https://static.api7.ai/uploads/2026/10/20/ChYoK0yi_http-connection-reuse-api-gateway-latency.webp)](https://api7.ai/blog/http-connection-reuse-api-gateway-latency)

Technology

October 20, 2026

#### [HTTP Connection Reuse: The Hidden API Latency Multiplier](https://api7.ai/blog/http-connection-reuse-api-gateway-latency)

Use Go 1.27's HTTP/1 change to diagnose connection reuse across clients, API gateways, and origins without hiding protocol or pool boundaries.

[API Gateway](https://api7.ai/tags/api-gateway)

[Performance](https://api7.ai/tags/performance)

[HTTP](https://api7.ai/tags/http)

[![API Gateway Cache Memory: Lessons from Cloudflare's 100 TB DNS Optimization](https://static.api7.ai/uploads/2026/09/01/O4BIgBdF_api-gateway-cache-memory-efficiency.webp)](https://api7.ai/blog/api-gateway-cache-memory-efficiency)

Technology

September 1, 2026

#### [API Gateway Cache Memory: Lessons from Cloudflare's 100 TB DNS Optimization](https://api7.ai/blog/api-gateway-cache-memory-efficiency)

Learn how cache-key cardinality, entry layout, TTLs, response limits, and realistic benchmarks keep API Gateway caches fast without wasting memory.

[API Gateway](https://api7.ai/tags/api-gateway)

[Performance](https://api7.ai/tags/performance)

[Caching](https://api7.ai/tags/caching)

[![API Gateway Multi-Tenancy: Routes Beat a Server per Endpoint](https://static.api7.ai/uploads/2026/11/24/GTCWjh37_api-gateway-multitenancy-routing.webp)](https://api7.ai/blog/api-gateway-multitenancy-routing)

Technology

November 24, 2026

#### [API Gateway Multi-Tenancy: Routes Beat a Server per Endpoint](https://api7.ai/blog/api-gateway-multitenancy-routing)

Design shared API ingress by separating listeners, hostnames, routes, policies, and upstreams instead of treating every endpoint as another server process.

[API Gateway](https://api7.ai/tags/api-gateway)

[Multi-Tenancy](https://api7.ai/tags/multi-tenancy)

[API Routing](https://api7.ai/tags/api-routing)
