Skip to content

load_balancer ​

load_balancer proxies each connection to one of several upstreams, with weighted round-robin, random or least-connections selection and active/passive health checks.

yaml
server:
  tcp:
    middlewares:
      db:
        load_balancer:
          strategy: least_conn
          retry: 1
          dial_timeout: 3s
          servers:
            - address: 10.0.0.1:5432
              weight: 2
            - address: 10.0.0.2:5432
          health_check:
            interval: 10s
            timeout: 2s
            unhealthy_threshold: 2
          passive_health_check:
            max_fails: 3
            fail_timeout: 30s
FieldDefaultDescription
servers[].addressUpstream host:port.
servers[].weight1Relative weight.
strategyround_robinround_robin (smooth weighted), random (weighted) or least_conn (open connections / weight).
retry0Dial other upstreams when dialing fails.
dial_timeout10sDial timeout.
disable_naglefalseDisable Nagle's algorithm.
proxy_protocolfalseSend a PROXY protocol header to the upstream.
proxy_protocol_version11 or 2.
health_checkActive check, see below.
passive_health_checkPassive check, see below.

Health checks ​

The active check opens a TCP connection to every upstream:

FieldDefaultDescription
interval10sTime between checks.
timeout5sDial timeout of the check.
healthy_threshold1Consecutive successes to mark healthy.
unhealthy_threshold1Consecutive failures to mark unhealthy.

The passive check counts dial failures of real connections. After max_fails failures within fail_timeout the upstream is skipped for fail_timeout.

Unhealthy upstreams are skipped. When every upstream is unhealthy, turna still tries them (fail open).