FULL AI ANALYSIS

Redis replicas fall behind and AOF rewrite blocks during high client churn after lowering tcp-keepalive

Generated Oct 28, 2026, 9:44:48 AM

Analysis summary

Lower tcp-keepalive increases socket churn and earlier detection of dead peers, raising connection teardown/establishment rate and kernel TIME_WAIT load. High connection turnover increases work for Redis (client table churn, buffers), which competes with AOF rewrite child for IO and CPU, elongating rewrite duration and blocking replication progress. AOF rewrite is IO/CPU bound; combined with frequent short connections it causes master to stall servicing replication handshake and build large replication backlog.

Possible causes

Increased socket churn from low tcp-keepalive causing higher CPU/IO pressure and longer AOF rewrite times

85%

AOF rewrite scheduled too frequently due to rapid dataset change from many short-lived writes

60%

Insufficient repl-backlog-size causing more full resyncs under transient lag

50%

Kernel ephemeral port exhaustion/timewait overload slowing new connections and socket teardown

40%

Suggested fixes

1

Diagnostic step 1

Restore tcp-keepalive to a higher default (e.g., 300s) and test under load to confirm client churn reduces.

2

Diagnostic step 2

Tune vm.max_map_count and net.ipv4.tcp_tw_reuse / tcp_fin_timeout to mitigate TIME_WAIT pressure cautiously, and monitor ephemeral port usage.

3

Diagnostic step 3

Increase repl-backlog-size and replication timeout on replicas to reduce full resyncs during transient spikes.

4

Diagnostic step 4

Stagger or throttle client connection bursts at the app layer or use connection pooling/proxy to reduce churn.

5

Diagnostic step 5

Adjust AOF policy: increase auto-aof-rewrite-percentage/size thresholds, or schedule rewrites during low load windows.