我使用mongodb來管理設備日誌數據。目前,它有超過一百萬份文件。該文檔包含超過30個與嵌入字段相結合的字段。現在,當我插入新文檔時,速度非常慢。插入成本超過1000毫秒。從慢查詢OPS,我得到的日誌是這樣的:mongodb插入非常慢
{
"op" : "insert",
"ns" : "xxx.LogDeviceReport",
"query" : {
"_id" : ObjectId("xxxx"),
"deviceId" : ObjectId("xxxx"),
"en" : "xxxxxx",
"status" : 1,
'other fields, more than 30 fields...'
...
...
},
"ninserted" : 1,
"keyUpdates" : 0,
"writeConflicts" : 0,
"numYield" : 0,
"locks" : {
"Global" : {
"acquireCount" : {
"w" : NumberLong(2)
}
},
"MMAPV1Journal" : {
"acquireCount" : {
"w" : NumberLong(3)
}
},
"Database" : {
"acquireCount" : {
"w" : NumberLong(2)
}
},
"Collection" : {
"acquireCount" : {
"W" : NumberLong(1)
},
"acquireWaitCount" : {
"W" : NumberLong(1)
},
"timeAcquiringMicros" : {
"W" : NumberLong(1477481)
}
},
"oplog" : {
"acquireCount" : {
"w" : NumberLong(1)
}
}
},
"millis" : 977,
"execStats" : {
},
"ts" : ISODate("2016-08-02T22:01:01.270Z"),
"client" : "xxx.xxx.xxxx",
"allUsers" : [
{
"user" : "xxx",
"db" : "xxx"
}
],
"user" : "[email protected]"
}
我查了指數,就像這樣:
[
{
"v" : 1,
"key" : {
"_id" : 1
},
"name" : "_id_",
"ns" : "xxx.LogDeviceReport"
},
{
"v" : 1,
"key" : {
"time" : 1
},
"name" : "time_1",
"ns" : "xxx.LogDeviceReport",
"expireAfterSeconds" : 604800,
"background" : true
}
]
只有一個_id索引和時間TTL指數,沒有任何其它指標。
我猜'查詢'減慢了操作。在mongodb文檔中,它告訴只有_id將被檢查唯一,但是在日誌中,'查詢'中的所有字段是否有關係?
如果不是這個原因,是什麼讓它如此緩慢?誰能幫我 ?
30場似乎像一個可怕的很多。除了這個問題外,可能還需要添加更多的表格並減少表格之間的信息。 – Carcigenicate
集合上有多少個索引?索引相對於可用RAM有多大?每個插入操作都需要更新每個索引;大量索引將增加集合上每個插入的開銷。 –
...作爲亞當問題的附錄:這些索引中有多少被聲明爲唯一的? – mtj