我刚开始使用mongodb。我使用ssd stoarge处理38GB数据集(6800万个文档)。 但性能是通过索引完成的,也没有索引。它使用如此多的ram进行简单的查找查询,有两个字段,没有cpu使用。
花了18分钟才能获得160万条记录。有什么因素有助于提高单节点的mongodb性能?
我的文档看起来像这样:
{ "_id" : ObjectId("55e7eec02756dd0f1e693b72"),
"categorieId" : 2,
"title" : "AntiMalware",
"messageValue" : " #\"Antimalware: \"Windows Defender\" is Not Updated and Running\"#",
"timestamp" : "8/19/2015 11:06:24 AM",
"resultStatusId" : 2,
"messageFormat" : "Text",
"titleId" : 1,
"resultStatus" : "Warning",
"antiMalwareName" : "Comodo Antivirus",
"categories" : "Security" }
我的索引位于titleId
和resultStatusId
。
我的查询是:
db.collection.find({"titleId":21, resultStatusId:1})
解释输出是:
{
"queryPlanner" : {
"plannerVersion" : 1,
"namespace" : "techHealLogAnalysis.techHealTestLogData",
"indexFilterSet" : false,
"parsedQuery" : {
"$and" : [
{
"resultStatusId" : {
"$eq" : 1
}
},
{
"titleId" : {
"$eq" : 21
}
}
]
},
"winningPlan" : {
"stage" : "FETCH",
"inputStage" : {
"stage" : "IXSCAN",
"keyPattern" : {
"titleId" : 1,
"resultStatusId" : 1
},
"indexName" : "titleId_1_resultStatusId_1",
"isMultiKey" : false,
"direction" : "forward",
"indexBounds" : {
"titleId" : [
"[21.0, 21.0]"
],
"resultStatusId" : [
"[1.0, 1.0]"
]
}
}
},
"rejectedPlans" : [ ]
},
"executionStats" : {
"executionSuccess" : true,
"nReturned" : 1671842,
"executionTimeMillis" : 1108805,
"totalKeysExamined" : 1671842,
"totalDocsExamined" : 1671842,
"executionStages" : {
"stage" : "FETCH",
"nReturned" : 1671842,
"executionTimeMillisEstimate" : 177670,
"works" : 2143234,
"advanced" : 1671842,
"needTime" : 0,
"needFetch" : 471391,
"saveState" : 471391,
"restoreState" : 471391,
"isEOF" : 1,
"invalidates" : 0,
"docsExamined" : 1671842,
"alreadyHasObj" : 0,
"inputStage" : {
"stage" : "IXSCAN",
"nReturned" : 1671842,
"executionTimeMillisEstimate" : 1470,
"works" : 1671843,
"advanced" : 1671842,
"needTime" : 0,
"needFetch" : 0,
"saveState" : 471391,
"restoreState" : 471391,
"isEOF" : 1,
"invalidates" : 0,
"keyPattern" : {
"titleId" : 1,
"resultStatusId" : 1
},
"indexName" : "titleId_1_resultStatusId_1",
"isMultiKey" : false,
"direction" : "forward",
"indexBounds" : {
"titleId" : [
"[21.0, 21.0]"
],
"resultStatusId" : [
"[1.0, 1.0]"
]
},
"keysExamined" : 1671842,
"dupsTested" : 0,
"dupsDropped" : 0,
"seenInvalidated" : 0,
"matchTested" : 0
}
}
},
"serverInfo" : {
"host" : "instance-7",
"port" : 27017,
"version" : "3.0.6",
"gitVersion" : "1ef45a23a4c5e3480ac919b28afcba3c615488f2"
},
"ok" : 1
}
答案 0 :(得分:2)
具有大型数据集和高吞吐量应用程序的数据库系统可能会挑战单个服务器的容量。较大的数据集超过了单台机器的存储容量。最后,大于系统RAM的工作集大小会强调磁盘驱动器的I / O容量。为您的案例部署分片可能非常有用。查看以下链接后。