Skip to content

Balancing

Illarion Kovalchuk edited this page Jul 9, 2020 · 8 revisions

Balancing strategy is a way gobetween select backends (from discovery backends pool) for new client connection. It's defined in balance property within [servers.<name>], and is weight by default.

weight

Select backend from discovery pool with probability based on backends weights and optionally specified priority.

priority The priority of the target host. Gobetween will attempt to contact the target host with the lowest-numbered priority it can reach. Target hosts with the same priority will be tried in an order defined by the weight field.

weight The weight field specifies a relative weight for entries with the same priority. Larger weights will be given a proportionately higher probability of being selected. Use Weight 0 when there isn't any server selection to do. Backends with weight 0 are not elected if there backends with higher weight.

Backends with negative weight or priority are ignored.

For example, for backends pool:

[
    "host1 weight=1 priority=1"
    "host2 weight=2 priority=1"
]

host1 will be selected with probability 75%, and host2 will be selected in 25% cases.

If weight for all backends are the same, backend will be selected randomly.

iphash

Target backend will be calculated using hash function of client ip address mod backends count. Note if backends pool changes (for example, due discovery), client may be proxied to a different backend.

iphash1

(since 0.6.0) Target backend will be calculated using hash function of client ip address in a way that if some backend goes down, only clients of the affected backend will be proxied to another backends. When affected backend gets restored, only its clients will be rebalanced back to it. If some new backends are added (by dynamic discovery), behavior is the same as iphash has. If some backends are removed from list (by dynamic discovery), only clients of removed backends get rebalanced to other backends.

leastconn

gobetween will select backends with least connections to it.

roundrobin

It's most simple balancing strategy, and each new connection will be proxies to next backend in the backends pool successively.

leastbandwidth

(since 0.3.0) Backends with least sum of rx/tx per second traffic will be selected for next request. Note that rx/tx per second values are calculated with 2 seconds interval so changes in bandwidth won't be instantly applied.