Elasticsearch7系列下同索引主分片分布不均衡思考:修订间差异
来自三线的随记
(创建页面,内容为“es版本: 7.17.5 现象: > cat es-shard-status-sw_segment-20250428|grep " p " | greep es-data-ssd-0|wc -l 26 > cat es-shard-status-sw_segment-20250428|grep " p " | grep es-data-ssd-1|wc -l 27 > cat es-shard-status-sw_segment-20250428|grep " p " | grep es-data-ssd-2|wc -l 72 > cat es-shard-status-sw_segment-20250428|grep " p " |grep es-data-ssd-3|wc -l 29 > cat es-shard-status-sw_segment-20250428|grep " p " |grep es-data-ssd-4|wc -l 26 k 可…”) |
小 (Admin移动页面Elasticsearch7系列下同索引主分片分布不均衡随记至Elasticsearch7系列下同索引主分片分布不均衡思考,不留重定向) |
(没有差异)
| |
2025年4月29日 (二) 00:08的版本
es版本: 7.17.5
现象:
> cat es-shard-status-sw_segment-20250428|grep " p " | greep es-data-ssd-0|wc -l 26 > cat es-shard-status-sw_segment-20250428|grep " p " | grep es-data-ssd-1|wc -l 27 > cat es-shard-status-sw_segment-20250428|grep " p " | grep es-data-ssd-2|wc -l 72 > cat es-shard-status-sw_segment-20250428|grep " p " |grep es-data-ssd-3|wc -l 29 > cat es-shard-status-sw_segment-20250428|grep " p " |grep es-data-ssd-4|wc -l 26
k
可以看到 sw_segment-20250428 这个索引在不同节点上,主分片分布非常不均衡,如果这个索引写入量/数据量很大的话,很容易导致 IO 相对其他实例有很大的差异
但是经过查询后发现,在整个集群所有分片中,主分片在所有es 实例中分布较为均衡
而es7系列原生自带的 balance 行为不支持针对同 index 的 primary shard 进行干预 (8.12 有 cluster.routing.allocation.balance.write_load 的权重配置)
这时候可以利用index total_shards_per_node选项来进行较为十分不灵活不优雅的干预,可以在索引初始化前设置该配置,以强制每一个es实例分布一样数量的分片数量。也可以为了长期打算,将total_shards_per_node数量配置为该索引的分片数 / (集群中可调度该索引分片的es实例数 - 1)
相关社区issue: https://github.com/elastic/elasticsearch/issues/41543