Diagnosing whether systemd LimitNOFILE or TasksMax caps cause connection pool exhaustion on Rocky Linux 8/9
0 reputation · 24 Nov 2024, 09:27 UTC
0 reputation · 24 Nov 2024, 09:27 UTC
Determine whether per-service systemd resource ceilings — LimitNOFILE (file descriptors) or TasksMax (threads/processes) — are the first bottleneck hit when a connection pool exhausts on Rocky Linux 8 or 9.
Rocky 9 defaults to cgroup v2 while Rocky 8 uses hybrid or v1 unless configured, changing how limits are enforced and observed. Default LimitNOFILE (1024 soft) and TasksMax (derived from kernel.pid_max) differ between releases and systemd versions. Raising either limit without checking kernel-wide fs.file-max and kernel.pid_max may shift the bottleneck rather than remove it. The OS cannot indicate whether the correct fix is raising the systemd ceiling or reducing the application pool size; that decision requires application-level pool metrics.
30775 reputation · 24 Nov 2024, 15:17 UTC
1. Identify the error type that appears when the connection pool stalls:
EMFILE (Too many open files) ⇒ LimitNOFILE is the likely ceiling.cannot create new native thread or clone(2): Resource temporarily unavailable ⇒ TasksMax is the likely ceiling.2. Verify live consumption against the configured ceilings using the commands below (they work on both cgroup v1 and v2).
systemctl show <unit> -p LimitNOFILE,TasksMax,TasksCurrent,MainPIDls /proc/$(systemctl show -p MainPID --value <unit>)/fd | wc -lcat /proc/$(systemctl show -p MainPID --value <unit>)/status | grep Threads cat /sys/fs/cgroup/<slice>/<unit>/pids.current (cgroup v1)cat /sys/fs/cgroup/system.slice/<unit>/pids.current (cgroup v2)3. Compare the live counts to the ceilings. If Threads or pids.current is close to TasksMax, the task ceiling is hit. If the FD count is near LimitNOFILE, the file‑descriptor ceiling is hit.
sysctl fs.file-max – maximum number of file descriptors system‑wide.sysctl fs.file-nr – current usage (allocations, inodes, etc.).sysctl kernel.pid_max – maximum PID value; TasksMax defaults to roughly 15% of this.sysctl kernel.threads-max – maximum number of threads system‑wide./etc/security/limits.d for per‑user nofile and nproc limits that might be hit before systemd.Raising a service’s LimitNOFILE or TasksMax above these kernel caps will have no effect; the kernel limits win silently.
Do you see EMFILE errors in the application logs, or do you see fork/clone failures such as cannot create new native thread?
Use the commands above to map live usage to configured ceilings, verify kernel limits, and then either raise the appropriate systemd ceiling or shrink the application pool. This approach ensures you hit the real bottleneck, not an arbitrary cap.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.