curr_connections trends upward with no corresponding traffic increase, edging toward the -c ceiling (default 1024). When it hits the limit, the listen socket disables: accepting_conns flips to 0 and new client TCP connects are refused. To the application it looks like memcached is down. To memcached it is idle and healthy on the connections it already holds.
Most of the time this is not a memcached bug. It is a client-side problem: connections opened and never returned, a broken or absent pool, or a fleet of application instances each holding more sockets than you accounted for. The server is the victim, not the cause.
The reflex fix is “raise -c”. That buys runway but masks the leak, and it pushes you toward response_obj_oom once connection buffer memory becomes the constraint instead of slot count. The real work is deciding whether you have a leak (curr_connections grows, total_connections rate is normal) or churn (curr_connections is stable, total_connections rate is very high), then tracing it to the offending client.
What this means
Memcached has a hard connection limit set by -c (default 1024). A main listener thread accepts connections and hands them round-robin to worker threads (-t, default 4). When curr_connections reaches max_connections, the listen socket is temporarily disabled: listen_disabled_num increments, accepting_conns reads 0, and new connects are rejected. The cumulative duration is captured in time_in_listen_disabled_us.
The cliff is binary: below the limit everything works, at the limit new clients are denied with no graceful degradation. The useful window for diagnosis is the slope, not the cliff.
curr_connections is a gauge that includes memcached’s own internal connections (the listening socket, internal pipe, and management sockets), typically a baseline of 3 to 5. It also counts your monitoring agents. The “real” client count is a few lower than the raw number, and capacity planning needs to reserve slots for both.
Two distinct failure modes produce a “connections are a problem” symptom, and the remediation differs for each:
- Leak.
curr_connectionsgrows monotonically.total_connectionsrate is normal or only mildly elevated. Sockets are opened and held, never closed. This is the dangerous one: it does not self-correct, and the only outcomes are hitting-cor restarting the offending clients. - Churn.
curr_connectionsis roughly stable, buttotal_connectionsrate is very high. Clients connect, issue a request, disconnect, and repeat.curr_connectionscan look fine in a dashboard and then spike when churn outpaces TIME_WAIT reaping on the host.
Churn tends to show up as client-side TIME_WAIT exhaustion or as elevated total_connections rate rather than as a monotonic curr_connections rise.
flowchart TD
A["curr_connections trending up"] --> B{"total_connections rate high?"}
B -- No --> C["Leak: sockets held open"]
B -- Yes --> D{"curr_connections stable?"}
D -- Yes --> E["Churn: connect/disconnect cycling"]
D -- No --> F["Leak + churn: investigate both"]
C --> G["Per-client socket count via ss"]
E --> H["Enable client-side pooling"]
C --> I["Fix pool / close paths in app"]
F --> GCommon causes
| Cause | What it looks like | First thing to check |
|---|---|---|
| Client connection leak | curr_connections climbs steadily; total_connections rate is modest | Per-client socket count via ss -tnp grouped by peer IP |
| Missing or broken pooling | curr_connections tracks app instance count; every request opens a new socket | total_connections rate vs cmd_get rate |
-c too low for fleet size | curr_connections plateaus near max; listen_disabled_num increments | curr_connections / max_connections ratio |
OS ulimit below -c | Connections fail before max_connections; client-side errors | ulimit -n for the memcached process |
| Idle connections held by long-lived workers | curr_connections stable but high; cmd_get rate modest | Per-client connection count and per-client idle time |
| Monitoring and agent connections | curr_connections includes baseline 3 to 5 plus agents | Count non-application sources in ss output |
Quick checks
These are read-only and safe to run during an incident.
# Daemon responsiveness and version
echo "version" | nc -q1 localhost 11211
# Current vs max connections, accept state, and rejection counters
echo "stats" | nc -q1 localhost 11211 \
| grep -E "STAT (curr_connections|max_connections|accepting_conns|listen_disabled_num|total_connections|rejected_connections|time_in_listen_disabled_us)"
# Two samples of total_connections to compute the new-connection rate
T0=$(echo "stats" | nc -q1 localhost 11211 | awk '/STAT total_connections/{print $3}'); sleep 10
T1=$(echo "stats" | nc -q1 localhost 11211 | awk '/STAT total_connections/{print $3}')
echo "new_conns_per_sec: $(( (T1 - T0) / 10 ))"
# OS file descriptor limit for the memcached process (must be >= max_connections)
PID=$(pgrep -x memcached); cat /proc/$PID/limits | grep "open files"
# Per-client connection count, ranked
# $5 is the peer address:port; -p adds local process names if run as root
ss -tnp | grep ":11211" | grep ESTAB | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -rn | head
# TIME_WAIT count on the memcached port (client-side churn indicator)
ss -tan state time-wait | grep ":11211" | wc -l
The ss -tnp peer IPs are visible without root. Root is needed for -p to resolve the local process name, which confirms the connections belong to memcached but is not required to identify offending clients.
How to diagnose it
- Confirm it is a leak, not churn. Sample
total_connectionstwice over a 10 to 30 second window. Ifcurr_connectionsis climbing buttotal_connectionsrate is low, sockets are being held open: a leak. Ifcurr_connectionsis roughly flat buttotal_connectionsrate is high, clients are churning through connects. The two need different fixes. - Compute runway. Use
(max_connections - curr_connections) / new_connection_rate. If the leak adds 5 connections per minute and you have 200 slots free, you have 40 minutes. That tells you whether this is a “page now” or a “fix in the next deploy” problem. - Find the offending client. Group established connections by peer IP. A single application host holding hundreds of sockets is the leak source. A broad, even distribution means the problem is fleet-wide pooling policy, not one bad instance.
- Check whether the OS fd limit is the real ceiling.
cat /proc/$PID/limits | grep "open files"must be at leastmax_connections. If the kernel limit is lower than-c, the kernel wins and connections fail before memcached’s own counter trips. - Check for server-side buffer pressure. If
curr_connectionsis very high, watchresponse_obj_oom(since 1.6.0). Connection buffers are allocated outside the-mslab pool, and raising-cwithout considering process memory can trigger response object OOMs that close otherwise healthy connections. - Rule out a server-side leak.
connection_structuresshould trackcurr_connectionsroughly. If it grows well out of proportion to live connections, that points to an internal accounting issue rather than a client problem.
Metrics and signals to monitor
| Signal | Why it matters | Warning sign |
|---|---|---|
curr_connections / max_connections | Primary gauge of slot pressure | Sustained above 0.7, or any monotonic climb |
total_connections rate | Distinguishes leak from churn | High rate with flat curr_connections = churn |
accepting_conns | Real-time accept state | Flips to 0 the moment the limit is hit |
listen_disabled_num | Count of listener-disable transitions | Any increment means the limit was reached |
time_in_listen_disabled_us | Cumulative time spent refusing connections | Increasing rate means sustained saturation |
rejected_connections | Clients actively turned away | Any non-zero value in production |
conn_yields | Per-event fairness (-R, default 20) | Sustained high rate means a client is pipelining aggressively |
response_obj_oom | Connection buffer memory exhaustion | Non-zero when curr_connections is very high |
OS ulimit -n for the process | Hard ceiling independent of -c | Lower than max_connections |
| Client-side TIME_WAIT count | Churn indicator on the client host | Thousands of TIME_WAIT sockets to port 11211 |
Fixes
Leaking client connections
A leak means sockets are opened and never closed. The memcached side cannot fix this. The work is in the application.
- Identify the offending client from the
ssgrouping above. - Audit every code path that constructs a memcached client. Look for paths that create a client per request, per thread, or per loop iteration without a corresponding close or return-to-pool.
- If the client library exposes pool metrics (max size, idle count, active count), check whether active count grows without bound under load. A correctly bounded pool should plateau, not climb.
- Restarting the offending application instances reclaims the sockets immediately, but only buys time. Without a code or config fix the leak returns.
Restarting clients is disruptive and loses in-process state, but it is faster than waiting for a code deploy when you are hours from the limit.
Missing or disabled pooling
If every request opens a new TCP connection, total_connections rate is high and curr_connections may look stable until TIME_WAIT or ephemeral port exhaustion on the client causes a spike. This is churn, not a leak.
- Enable persistent connections in the client library. Most memcached clients support a persistent connection mode or a built-in pool.
- For PHP specifically, persistent connections only help if the PHP process survives between requests. With short-lived PHP-CGI or mod_php workers, “persistent” connections are effectively non-persistent because the process dies and takes the socket. PHP-FPM with persistent connection IDs is the working pattern.
- Set an idle timeout on the pool so abandoned connections are reaped. Without one, a slow leak in pool accounting still accumulates.
- Verify the pool size is bounded. A pool with no max is just a leak with extra steps.
-c too low for the fleet
The default 1024 is often too low for production. If you have 50 application instances each holding 30 persistent connections, you are already at 1500.
- Raise
-c. This requires a restart unless your deployment supports runtime reconfiguration. - Account for monitoring agents and the 3 to 5 internal baseline connections.
- Keep
curr_connectionsbelow 70% ofmax_connectionsas a planning target. The headroom absorbs reconnection storms after deploys and brief bursts.
Each connection consumes roughly 10KB of buffer memory outside the slab pool. Raising -c to 50000 without considering process memory risks response_obj_oom. Size the limit against actual peak persistent connection count plus headroom, not against a round number.
OS ulimit below -c
If /proc/$PID/limits shows an open-files limit lower than max_connections, the kernel enforces the lower number and connections fail before memcached’s own counter trips.
- Raise the memcached process fd limit via systemd
LimitNOFILE, an init scriptulimit -n, or the orchestrator’s equivalent. - In containerized deployments, check the container runtime’s ulimit. Docker inherits a default that may be much lower than expected. A common workaround is
--ulimit nofile=16384on thedocker runcommand. - The fd limit must cover
max_connectionsplus listening sockets plus internal use.
Prevention
- Alert on
curr_connections / max_connectionsabove 0.7. This is the warning band. The composite Connection Exhaustion page (accepting_conns = 0 sustained) is the emergency band. - Track
total_connectionsas a rate, not just a counter. Churn shows up here before it shows up incurr_connections, and a sudden rate increase often precedes a deploy-induced reconnection storm. - Size
-cagainst peak persistent connection count plus 30% headroom. Recompute whenever the application fleet scales horizontally. - Verify OS fd limits in the same runbook step as
-c. The two ceilings must agree. - Instrument client-side pool metrics. Active, idle, and pending-acquire counts per pool tell you whether the problem is server pressure or client pressure before you touch memcached.
- Watch
response_obj_oomwhen running high connection counts. It is the signal that you raised-cpast what the process memory can support. - Alert on any increment of
rejected_connectionsorlisten_disabled_num. Both mean a client was denied service.
How Netdata helps
- Per-second
curr_connectionsandmax_connectionsratio lets you see the slope, not just snapshots. The rate of climb tells you whether you have minutes or hours of runway. total_connectionsrate as a derived metric separates leak from churn at a glance. A climbingcurr_connectionswith a flattotal_connectionsrate is the leak signature.accepting_conns,listen_disabled_num,time_in_listen_disabled_us, andrejected_connectionstogether form the connection exhaustion composite. Correlating them withcmd_getandcmd_setrates confirms whether saturation is traffic-driven or leak-driven.- ML anomaly detection on the
curr_connectionsslope catches slow leaks that never trip a static threshold but still drain the slot pool over hours. conn_yieldsandresponse_obj_oomsurface the secondary effects of high connection counts: unfair pipelining and buffer memory exhaustion. These appear beforeaccepting_connsflips.- Correlation with per-host TCP connection state (TIME_WAIT, ESTAB counts from the OS-level collector) localizes churn to specific client hosts without needing root on the memcached box.
Related guides
- Memcached connection limit reached: accepting_conns=0 and clients being refused
- Memcached connection refused: telling a dead process from a hung or full one
- How Memcached actually works in production: a mental model for operators
- Memcached eviction cascade: when a full cache overloads the backend
- Memcached evictions climbing: the cache is full and discarding live data
- Memcached evicted_time low: distinguishing healthy turnover from cache thrash
- Memcached memory utilization: bytes vs limit_maxbytes and why the global number lies
- Memcached hit ratio dropping: reading get_hits, get_misses, and cache effectiveness
- Memcached high miss rate: separating cold start, new key patterns, and memory pressure
- Memcached evicted_unfetched and expired_unfetched: caching data nobody ever reads
- Memcached cas_badval climbing: check-and-set contention and lost updates
- Memcached incr/decr misses: evicted counters that silently break rate limiters and locks






