我在分片群集上遇到插入速度慢的问题。我的设置包含5个分片,每个分片至少有3个副本集成员。就网络拓扑而言,一组RS成员生活在Rackspace Cloud中,其余成员都在AWS上。在所有
上运行2.4.6我正在用Java处理文件并将其写入MongoDB。每个文件大约为60MB,文件的结果数据在DB中最终为~160MB。我正在从我的Java应用程序连接到mongos。我正在对_id(自动生成的ObjectID)的哈希值进行分片,并且我已将写入关注设置为UNACKNOWLEDGED。
如果我写一个未整理的集合,我可以在大约90秒内写完整个文件。如果我写一个分片集合,它需要约20分钟!
到目前为止,我已经完成了一些初步调试:
我注意到的事情:
主分片上的主节点几乎处于80%的写锁定状态。其他初选徘徊在5%左右,偶尔飙升至30%。辅助人员都坐在5%左右,偶尔会出现15%的飙升
sh.status()显示偶数块分布,但db.collection.stats()显示主分片有一个计数&尺寸是其他四个碎片的两倍
日志或彩信中没有其他明显错误
有关如何进一步调试此问题的任何想法?
使用sh.status()
的输出进行更新 prod.collection
shard key: { "_id" : "hashed" }
chunks:
rs1 8
rs2 8
rs3 8
rs4 8
rs0 8
too many chunks to print, use verbose if you want to force print
来自collection.stats()的输出
mongos> db.collection.stats()
{
"sharded" : true,
"ns" : "prod.collection",
"count" : 879837,
"numExtents" : 76,
"size" : 2210698416,
"storageSize" : 2653114368,
"totalIndexSize" : 73526768,
"indexSizes" : {
"_id_" : 31526656,
"_id_hashed" : 42000112
},
"avgObjSize" : 2512.6226971586784,
"nindexes" : 2,
"nchunks" : 20,
"shards" : {
"rs0" : {
"ns" : "prod.collection",
"count" : 300130,
"size" : 754047552,
"avgObjSize" : 2512.403131976144,
"storageSize" : 873058304,
"numExtents" : 17,
"nindexes" : 2,
"lastExtentSize" : 232005632,
"paddingFactor" : 1.0000000000001465,
"systemFlags" : 1,
"userFlags" : 0,
"totalIndexSize" : 24037440,
"indexSizes" : {
"_id_" : 9753968,
"_id_hashed" : 14283472
},
"ok" : 1
},
"rs1" : {
"ns" : "prod.collection",
"count" : 139598,
"size" : 350820064,
"avgObjSize" : 2513.07371165776,
"storageSize" : 470589440,
"numExtents" : 15,
"nindexes" : 2,
"lastExtentSize" : 127299584,
"paddingFactor" : 1.000000000000052,
"systemFlags" : 1,
"userFlags" : 0,
"totalIndexSize" : 11626272,
"indexSizes" : {
"_id_" : 5060944,
"_id_hashed" : 6565328
},
"ok" : 1
},
"rs2" : {
"ns" : "prod.collection",
"count" : 149987,
"size" : 376944272,
"avgObjSize" : 2513.179622233927,
"storageSize" : 470593536,
"numExtents" : 15,
"nindexes" : 2,
"lastExtentSize" : 127299584,
"paddingFactor" : 1.0000000000000484,
"systemFlags" : 1,
"userFlags" : 0,
"totalIndexSize" : 12713680,
"indexSizes" : {
"_id_" : 5674144,
"_id_hashed" : 7039536
},
"ok" : 1
},
"rs3" : {
"ns" : "prod.collection",
"count" : 140235,
"size" : 352293776,
"avgObjSize" : 2512.167262095768,
"storageSize" : 377905152,
"numExtents" : 14,
"nindexes" : 2,
"lastExtentSize" : 104161280,
"paddingFactor" : 1.0000000000000422,
"systemFlags" : 1,
"userFlags" : 0,
"totalIndexSize" : 11863376,
"indexSizes" : {
"_id_" : 5110000,
"_id_hashed" : 6753376
},
"ok" : 1
},
"rs4" : {
"ns" : "prod.collection",
"count" : 149887,
"size" : 376592752,
"avgObjSize" : 2512.5111050324576,
"storageSize" : 460967936,
"numExtents" : 15,
"nindexes" : 2,
"lastExtentSize" : 124985344,
"paddingFactor" : 1.000000000000043,
"systemFlags" : 1,
"userFlags" : 0,
"totalIndexSize" : 13286000,
"indexSizes" : {
"_id_" : 5927600,
"_id_hashed" : 7358400
},
"ok" : 1
}
},
"ok" : 1
}
平衡器状态:
mongos> !sh.getBalancerState() && !sh.isBalancerRunning()
true