三台虚拟机搭建的Mongodb集群3.2.9版本,3个分片,每个分片总计2个复制集(一主一备),文档经常需要增删,总计1亿多条数据,DateSize 69G,StorgeSize 19G,索引7G。
一段时间后整个数据库查询和更新速度变慢,通过sh.status() 查看各表的chunks在各分片是分布均匀的,但实际数据80%以上是集中在shard2分片(实际数据只占用900多个chunks),发现shard1和shard2的chunks的shard key范围都是已删除数据的索引值,占用了chunks的资源导致没有按照实际900多个chunks均衡,这个是什么问题呢?如何解决?
db.records
shard key: { “_id” : 1 }
unique: true
balancing: true
chunks:
shard1 807
shard2 813
shard3 807
{ “_id” : { “$minKey” : 1 } } –>> { “_id” : “4aece07d87da46” } on : shard1 Timestamp(37, 0)
{ “_id” : “4aece07d87da46” } –>> { “_id” : “4aedca045d0d05” } on : shard3 Timestamp(38, 0)
{ “_id” : “4aedca045d0d05” } –>> { “_id” : “4aee10a6297649” } on : shard1 Timestamp(39, 0)
{ “_id” : “4aee10a6297649” } –>> { “_id” : “4aeed16843a67a” } on : shard3 Timestamp(40, 0)
… …
下面72%的数据和存储集中在shard2分片上:
mongos> db.record.getShardDistribution()
Shard shard1 at shard1/10.11.123.221:22001,10.11.123.231:22001
data : 9.47GiB docs : 22144466 chunks : 810
estimated data per chunk : 11.97MiB
estimated docs per chunk : 27338
Shard shard2 at shard2/10.11.123.231:22002,10.11.123.241:22002
data : 42.91GiB docs : 99995989 chunks : 816
estimated data per chunk : 53.85MiB
estimated docs per chunk : 122544
Shard shard3 at shard3/10.11.123.221:22003,10.11.123.241:22003
data : 7.36GiB docs : 17210136 chunks : 809
estimated data per chunk : 9.32MiB
estimated docs per chunk : 21273
Totals
data : 59.75GiB docs : 139350591 chunks : 2435
Shard shard1 contains 15.85% data, 15.89% docs in cluster, avg obj size on shard : 459B
Shard shard2 contains 71.81% data, 71.75% docs in cluster, avg obj size on shard : 460B
Shard shard3 contains 12.32% data, 12.35% docs in cluster, avg obj size on shard : 459B