HAProxy run queue rising: task backlog and scheduler pressure
HAProxy’s event loop processes every connection, request, health check, and timer as tasks scheduled across its threads. When tasks arrive faster than threads can drain them, they pile up in the run queue. That backlog is the earliest internal signal that HAProxy is CPU-saturated: it appears before latency spikes, before backend queuing, and before client timeouts.
It is also the signal to use when Idle_pct is meaningless. With busy-polling enabled, the event loop never sleeps, so Idle_pct sits near zero by design. The Run_queue field from show info and the per-thread counters from show activity are the replacement.
A rising run queue does not tell you why the scheduler is behind. The usual drivers are TLS handshake load, expensive ACL or regex evaluation, Lua scripts, and compression. The job is to confirm the backlog, find which threads and which work items cause it, and relieve the specific CPU consumer.
What this means
HAProxy multiplexes hundreds of thousands of connections across a small number of threads (nbthread). Each thread runs a poll loop: wait for I/O and timer events, wake the tasks that became runnable, execute them, repeat. Tasks are connection state machines, health checks, peers, stick-table expiry, and internal housekeeping.
Two fields in show info describe the scheduler’s position:
Tasks: total active tasks. Scales with connections and configured health checks. A size gauge, not a pressure gauge.Run_queue: tasks that are runnable but waiting for a thread. Healthy operation is zero or near zero. A sustained nonzero, growing value means work is arriving faster than threads can execute it.
show activity adds roughly 32 per-thread counters: loop iterations, poll timing, run-queue depth per thread. Two things matter: aggregate backlog, and skew. One thread carrying most of the work caps overall throughput even when the average looks fine.
The failure cascade:
flowchart TD A[CPU driver: TLS handshakes, ACL/regex, Lua, compression] --> B[Tasks stay runnable longer per loop] B --> C[Run_queue rising, per-thread backlog] C --> D[Slower accept and request dispatch] D --> E[Client-visible latency climbs] D --> F[Backend ctime rises, accept slows] E --> G[Timeouts, client aborts] C --> H[Kernel accept queue overflows - ListenOverflows] H --> I[SYNs dropped before HAProxy sees them]
The kernel accept queue step is the nasty part. When the event loop is too busy to call accept() promptly, new SYNs overflow net.core.somaxconn and are dropped silently. HAProxy’s own metrics show nothing wrong because those connections never reached user space.
Common causes
| Cause | What it looks like | First thing to check |
|---|---|---|
| TLS handshake load | SslFrontendKeyRate elevated, Run_queue rising, backends healthy | SslFrontendKeyRate and SslCacheLookups vs SslCacheMisses in show info |
| Complex ACL/regex evaluation | Run_queue tracks req_rate, not connection count; no single resource exhausted | Audit request rules for regex-heavy ACLs; correlate queue rise with request rate |
| Lua scripts in request/response path | Backlog skewed to specific threads or routes; latency rises on Lua-protected paths only | Identify which proxies use Lua actions; test by routing around them temporarily |
| Compression overhead | Idle_pct dropping (non-busy-polling), high comp_rsp, poor comp_in/comp_out ratio | Check whether compression is enabled and what fraction of traffic it processes |
| Thread imbalance (hot thread) | Aggregate counters moderate, one thread’s counters far above others in show activity | Per-thread brackets in show activity output |
| Busy-polling misread | Idle_pct-near-zero alerts firing, but Run_queue is actually zero | Confirm whether busy-polling is set; if so, ignore Idle_pct entirely |
| Insufficient threads for the hardware | All threads uniformly backlogged under normal load | Compare nbthread to available cores; check per-core CPU |
Quick checks
All read-only, via the runtime socket. Adjust the socket path for your deployment.
# 1. Scheduler position: run queue, tasks, idle
echo "show info" | socat unix-connect:/var/run/haproxy.sock stdio | \
grep -E "^(Tasks|Run_queue|Idle_pct|Uptime_sec):"
# 2. Per-thread activity counters (HAProxy 1.9+)
echo "show activity" | socat unix-connect:/var/run/haproxy.sock stdio
# 3. TLS handshake load (the usual prime suspect)
echo "show info" | socat unix-connect:/var/run/haproxy.sock stdio | \
grep -E "^(SslRate|SslFrontendKeyRate|SslCacheLookups|SslCacheMisses|CurrSslConns):"
# 4. Traffic volume for correlation
echo "show info" | socat unix-connect:/var/run/haproxy.sock stdio | \
grep -E "^(ConnRate|SessRate|CurrConns):"
# 5. Kernel accept queue overflow (event loop too busy to accept)
nstat -az | grep -i listen
# 6. System view: is HAProxy the CPU consumer, and on which cores
# (master-worker setups have multiple PIDs; include all of them)
top -H -p "$(pgrep -x haproxy | paste -sd,)"
# 7. Is compression active and busy
echo "show stat" | socat unix-connect:/var/run/haproxy.sock stdio | \
awk -F, '$2 == "FRONTEND" {print $1": comp_in="$52" comp_out="$53" comp_rsp="$55}'
# 8. Two samples of Run_queue 10 seconds apart to see the trend
for i in 1 2; do
echo "show info" | socat unix-connect:/var/run/haproxy.sock stdio | grep "^Run_queue:"
sleep 10
done
Notes on interpretation:
- A single
Run_queuesnapshot means little. Sample repeatedly: a backlog that recovers between samples is burst absorption; a backlog that grows monotonically is saturation. show activitycounters are 32-bit and wrap on busy instances. Compare deltas over short windows, not absolute values from long-running processes.show activityexists since HAProxy 1.9. On 2.7 and later, output shows an aggregated first column with per-thread values in brackets; older versions show per-thread values only.
How to diagnose it
Confirm the backlog is real. Take three
Run_queuesamples 5-10 seconds apart. Sustained nonzero values, especially rising, confirm scheduler pressure. RecordTasksandIdle_pct(if not busy-polling) for the same samples.Check whether you are in busy-polling mode. If
busy-pollingis set in the global section, disregardIdle_pctfor this entire diagnosis. It reads near zero on a perfectly healthy process. Run queue andshow activityare your only in-process saturation signals; per-core system CPU is the external check.Look for thread skew in
show activity. Compare per-thread run-queue depth and loop counters. One thread far ahead of the others means an affinity or distribution problem (for example, one listener thread absorbing all accepts). Uniform backlog across all threads means a global CPU deficit instead.Watch the loop timing counters. In
show activity, poll loop duration tells you whether each iteration is getting slower (tasks doing more work per pass) or the queue between passes is getting deeper (more tasks waking per pass). Slower iterations point at expensive per-task work: regex ACLs, Lua, compression. Deeper queues at normal iteration speed point at volume: handshake storms, connection floods.Identify the CPU driver. Walk the usual suspects in order of likelihood:
- TLS: is
SslFrontendKeyRateelevated versus baseline? Is the session cache effective (SslCacheMisses / SslCacheLookups)? A broken or undersized cache forces a full handshake on every connection. - Request-phase CPU: does the backlog track
req_rate(per-request work: ACLs, regex, Lua) orConnRate/SslFrontendKeyRate(per-connection work: TLS)? - Compression: if enabled, is a large share of responses being compressed while the proxy is CPU-bound?
- TLS: is
Rule out the invisible loss path. Check
ListenOverflows/ListenDropsand theConnRatevsSessRategap. If the event loop is too busy to accept, clients are already timing out at SYN and you will not see them in any HAProxy counter.Correlate with downstream symptoms. Backend
ctimerising with lowecon, and frontend latency rising while backendrtimestays flat, is the signature of HAProxy-side CPU saturation rather than a backend problem. Ifrtimeis rising too, you may be looking at a backend slowdown instead: see the 504 cascade guide linked below.
Metrics and signals to monitor
| Signal | Why it matters | Warning sign |
|---|---|---|
Run_queue (show info) | Direct measure of scheduler backlog | Sustained nonzero; rising across samples |
Tasks (show info) | Total active tasks, scales with connections | Growing without matching connection growth |
Idle_pct (show info) | Event loop headroom, when not busy-polling | < 20% sustained; meaningless with busy-polling |
show activity per-thread counters | Thread skew and loop behavior | One thread’s counters far above peers |
SslFrontendKeyRate (show info) | TLS handshake load, the dominant CPU cost | Spike above baseline or tested capacity |
SslCacheLookups / SslCacheMisses | Session resumption effectiveness | Miss rate climbing (full handshake per connection) |
ConnRate vs SessRate gap | Pre-accept connection loss | Widening gap during the incident |
ListenOverflows/ListenDrops (/proc/net/netstat) | Kernel dropping SYNs the loop can’t accept | Any acceleration during backlog |
Backend ctime, frontend latency vs backend rtime | Separates HAProxy-side CPU pain from backend slowness | ctime up, rtime flat |
comp_rsp, comp_in/comp_out | Compression CPU load | High compressed-response volume during backlog |
Fixes
TLS handshake load
- Fix session resumption first. If
SslCacheMissesis high relative to lookups, the cache is too small or tickets are being invalidated (for example by frequent reloads). Restoring resumption removes most of the handshake CPU cost immediately and is the cheapest real fix. - Reduce new-connection churn. Long keep-alive lifetimes and HTTP/2 amortize handshakes across many requests. Check whether clients or an upstream device are forcing one connection per request.
- Add threads or offload. If the load is genuine growth, raise
nbthreadtoward available cores (requires a reload; plan it) or move termination to a dedicated layer. Adding threads during an active saturation event is disruptive: treat it as a planned change, not a hot fix.
Expensive per-request work (ACLs, regex, Lua, compression)
- Simplify hot-path ACLs. Regex matching on every request multiplies cost by request rate. Prefer exact/string or map-based lookups where possible.
- Audit Lua actions. Blocking or long-running Lua in
http-request/http-responserules stalls the calling thread. Move work out of the request path or make the actions cheaper. - Restrict compression scope. Compress only compressible content types, or disable compression while CPU-bound. Compression trades CPU for bandwidth; when CPU is the scarce resource, the trade is wrong.
Thread imbalance
- If
show activityshows one thread doing most of the work, review listener binding and thread affinity configuration, and considerSO_REUSEPORT-based distribution. Verify with per-thread counters after the change; averages will hide the fix if it did not work.
When you cannot reduce the work
- Shed or shape load. Rate limiting at the frontend (
rate-limit sessions, stick-table based limits) caps the arrival rate so the backlog stops growing. This protects existing sessions at the cost of rejecting new ones. - Do not restart HAProxy as a first response. A restart drops all connections and resets all counters, destroying the evidence and briefly worsening client impact. If the process is healthy but saturated, the fix is less work or more capacity, not a new process.
Prevention
- Baseline the run queue. Record typical
Run_queuebehavior at daily peak so “rising” has meaning for your workload. The norm is zero or near zero; know your bursts. - Alert on the busy-polling-appropriate signal. If
busy-pollingis on, disableIdle_pctalerting and alert on sustainedRun_queue > 0or per-core CPU of HAProxy threads instead. If it is off, alert onIdle_pct < 20%sustained as the early warning andRun_queueas confirmation. - Watch the CPU drivers, not just the symptom. Trend
SslFrontendKeyRate, cache miss ratio, and compressed-response volume. These move before the run queue does. - Handle counter wrap.
show activitycounters are 32-bit. On high-traffic instances they wrap within the process lifetime; collect frequently, compute deltas, and treat resets on reload as new baselines (Uptime_sectells you when a reload happened). - Capacity-plan from peak loop headroom. When peak-hour
Idle_pcttrends below ~30% (non-busy-polling) or the run queue starts appearing at peak regularly, you are inside the headroom buffer. Scale before the backlog becomes continuous. - Keep
net.core.somaxconnand the SYN backlog sized for burst so a transiently busy loop absorbs connection bursts instead of silently dropping SYNs.
How Netdata helps
- Netdata collects HAProxy
show infoand stats CSV fields continuously, soRun_queue,Tasks,Idle_pct, andSslFrontendKeyRateare graphed at high resolution instead of sampled by hand during the incident. - Per-second collection makes the rate of rise visible, which is what separates burst absorption from true saturation; a single manual sample cannot show that.
- Correlating
SslFrontendKeyRateand SSL cache counters against the run queue on one dashboard answers the “is this TLS?” question in seconds rather than a socket session. - Backend
ctime,rtime, andeconalongside the scheduler signals confirm the backlog is HAProxy-side CPU pressure and not a backend slowdown masquerading as one. - System-level metrics (per-core CPU,
ListenOverflows) collected from the same host close the loop on thread skew and the silent SYN-drop path. - Anomaly detection on the run queue and handshake rate catches slow-building scheduler pressure during off-hours, before it coincides with peak traffic.
Related guides
- HAProxy scur approaching slim: the concurrent-session saturation signal
- HAProxy 504 Gateway Timeout: timeout server and the backend timeout cascade
- HAProxy backend queue building (qcur): requests waiting for a free server slot
- HAProxy connect time (ctime) high: network latency and backend accept-queue overflow
- HAProxy connection errors (econ): backend connections refused, timed out, or reset
- HAProxy 502 Bad Gateway: backend connection and response failures
- HAProxy 503 Service Unavailable: no server is available to handle this request
- HAProxy 5xx delta: telling HAProxy-generated errors from backend errors
- HAProxy backend losing servers: active server count and cascade risk
- HAProxy health checks green but the application is broken: when UP does not mean healthy
- HAProxy health check L4TOUT and L4CON: server marked DOWN and unreachable
- HAProxy health check L7STS: server DOWN on the wrong HTTP status






