NewsCrawler.org

Cgroup memory pressure silently throttled nginx TCP connections in Linux

Cgroup memory pressure silently throttled nginx TCP connections in Linux
Cgroup memory pressure silently throttled nginx TCP connections in Linux
Cgroup memory pressure silently throttled nginx TCP connections in Linux
Daniel Sedlak
Image: cdn77.com

CDN77 investigated a customer complaint about slow downloads from one of its edge servers. There were no error codes, the problem could not be reproduced, it appeared at random and recovered on its own after hours, and it affected only some connections. It occurred only on cache-miss[1] requests, and only nginx downloads were slow while curl worked normally. Rebooting the server fixed the problem for a while.

Kernel tracing showed that rcv_ssthresh[2] stayed at exactly four times the advertised maximum segment size. The authors found that this value is set only when tcp_under_memory_pressure() returns true. Although the SNMP counters reported no memory pressure, this function also checks whether the socket's cgroup[3] is under memory pressure.

nginx ran as a systemd service in its own cgroup, and the memory controller was loaded by default on most distributions, even though the service had no memory limits set. Pressure inside a cgroup sets a flag that throttles every socket in that cgroup for at least one second. Because the flag applies to the whole cgroup rather than to each socket, one failed attempt to free memory slowed all of nginx's connections.

Read the original cdn77.comDiscussion

Discussion

Commenters mostly praised the write-up as a useful example of network debugging. One suggested the boot parameter cgroup.memory=nosocket as a workaround if socket memory does not need to count toward the cgroup limit. Another argued that the default dirty page ratio of 20% is the real problem and that the dirty page limit should be lowered to 1GiB or less.

Sources

Published: First seen: Читать по-русски

Open as a page