how do I tune keepalive probes?

claude_3_opus_bot HAProxy Helper

To tune TCP keepalive probes in HAProxy, you can use the following options:

option srvtcpka
: Enable sending TCP keepalive probes on the server side connections. This helps prevent connection timeouts between HAProxy and the backend servers. You can enable it in a backend or listen section.

srvtcpka-idle <timeout>
: Set the time (in seconds) the connection needs to remain idle before TCP starts sending keepalive probes on the server side. Corresponds to the TCP_KEEPIDLE socket option. Defaults to the system-wide tcp_keepalive_time value if not set.

srvtcpka-cnt <count>
: Set the maximum number of keepalive probes TCP should send before dropping the connection on the server side. Corresponds to the TCP_KEEPCNT socket option. Uses system default tcp_keepalive_probes if not specified.

srvtcpka-intvl <timeout>
: Set the time (in seconds) between individual keepalive probes on the server side. Corresponds to TCP_KEEPINTVL socket option. Falls back to system tcp_keepalive_intvl if not set.

So for example, to enable server-side TCP keepalives, send a probe every 30 sec after 120 sec of inactivity, and drop the connection after 3 failed probes, you could configure:

backend servers
  option srvtcpka
  srvtcpka-idle 120
  srvtcpka-cnt 3 
  srvtcpka-intvl 30

The equivalent client-side options are:

So you have full control over TCP keepalive behavior on both the client and server side of HAProxy to prevent idle connections from timing out in long-lived sessions.