Total shards per node
The cluster-level shard allocator tries to spread the shards of a single index across as many nodes as possible. However, depending on how many shards and indices you have, and how big they are, it may not always be possible to spread shards evenly.
The following dynamic setting allows you to specify a hard limit on the total number of shards from a single index allowed per node:
index.routing.allocation.total_shards_per_node
The maximum number of shards (replicas and primaries) that will be allocated to a single node. Defaults to unbounded.
You can also limit the amount of shards a node can have regardless of the index:
cluster.routing.allocation.total_shards_per_node
The maximum number of shards (replicas and primaries) that will be allocated to a single node globally. Defaults to unbounded (-1).
index.routing.allocation.total_shards_per_node
這個參數(shù)可以控制單個索引在同一個結(jié)點上最多分配幾個shard。 默認(rèn)是無上限,因此在擴(kuò)容新結(jié)點的時候命雀,很可能一個索引的很多shard分到同一個node娃兽。 具體設(shè)置多少,需要根據(jù)集群結(jié)點數(shù)量和一個index shard總數(shù)量(包含主和副復(fù)制片)來定掀鹅。
例如10個node,index設(shè)置 5 primary + 5 replica。
設(shè)置index.routing.allocation.total_shards_per_node:1
可以保證這個索引在每個node上只分配一個shard丙者。 這樣設(shè)置好處是數(shù)據(jù)分布最均勻, 但是也有負(fù)面影響慢哈,比如如果有一個node掛了蔓钟,就會有一個shard無法分配,變成UNASSIGNED狀態(tài)卵贱。
如果設(shè)置index.routing.allocation.total_shards_per_node:2
滥沫,則可能數(shù)據(jù)均衡狀態(tài)不如設(shè)置為1那么理想侣集,但是可以容忍一個node掛掉,因為shard可以再分配到其他node兰绣。 這個設(shè)置結(jié)合shard balancing heuristics做全局調(diào)配應(yīng)該比較理想世分。