load_balancing
Specifies the algorithm of replicas selection that is used for distributed query processing. ClickHouse supports the following algorithms of choosing replicas:- Random (by default)
- Nearest hostname
- Hostname levenshtein distance
- Hostname longest common prefix
- Hostname longest common suffix
- In order
- First or random
- Round robin
Random (by Default)
Nearest Hostname
Hostname levenshtein distance
nearest_hostname, but it compares hostname in a levenshtein distance manner. For example:
Hostname longest common prefix
nearest_hostname, but the replica whose hostname shares the longest common prefix with the local hostname is preferred (the longer the common prefix, the higher the priority). Unlike nearest_hostname, which counts differing characters position by position, this strategy is not confused by hostnames whose numeric segments have different lengths. For example, for the local hostname sfe301:
sfe10101 is preferred because it shares the longest common prefix (sfe, length 3) with sfe301.
Replicas with equal common prefix length are chosen at random. In particular, when no replica shares any prefix with the local hostname (all common prefix lengths are zero), this strategy behaves exactly like random.
Hostname longest common suffix
hostname_longest_common_prefix, but the longest common suffix is compared instead of the prefix. This is useful when the data center identity is encoded as a suffix of the hostname. For example, for the local hostname et46gtghn.qc.localdomain:
ab999.qc.localdomain is preferred because it shares the longest common suffix (.qc.localdomain, length 15) with et46gtghn.qc.localdomain.
Replicas with equal common suffix length are chosen at random. In particular, when no replica shares any suffix with the local hostname (all common suffix lengths are zero), this strategy behaves exactly like random.
In Order
First or Random
first_or_random algorithm solves the problem of the in_order algorithm. With in_order, if one replica goes down, the next one gets a double load while the remaining replicas handle the usual amount of traffic. When using the first_or_random algorithm, the load is evenly distributed among replicas that are still available.
It’s possible to explicitly define what the first replica is by using the setting load_balancing_first_offset. This gives more control to rebalance query workloads among replicas.
Round Robin
round_robin policy is accounted).