CDN77 engineers investigated intermittent download slowdowns affecting some nginx cache-miss connections. Speeds could remain low for hours and recover without intervention; direct curl tests, other services, and neighboring servers were unaffected, while rebooting temporarily cleared the problem. Network paths, TCP settings, nginx configuration, system resources, and read/epoll behavior showed no cause. Kernel tracing instead revealed that affected TCP sockets had an unusually small receive-window threshold: four times the advertised maximum segment size. That value was being set when the kernel considered the socket under memory pressure, despite system-wide TCP pressure counters reporting none.
The hidden trigger was memory pressure recorded for nginx’s systemd cgroup. Linux checks both global TCP pressure and a socket’s cgroup pressure, and a reclaim shortfall can set a cgroup-wide flag that reduces the receive buffers of all its sockets. The flag can be raised when reclaim frees less than roughly 40 percent of pages scanned in a small, fixed two-megabyte window - not when the machine is actually short of free RAM. Cache-heavy workloads could therefore throttle nginx connections despite abundant memory. Moving nginx into the root cgroup stopped the effect because root cgroups do not receive this pressure signal. CDN77 also contributed a Linux change: since kernel 6.19, memory.events includes a sock_throttled counter to expose sockets throttled by this mechanism.
Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.