我們有一個包含近4000萬條記錄的MongoDB集合。目前這個系列的尺寸是5GB。存儲在此集合中的數據包含以下字段:MongoDB索引
_id: "MongoDB id"
userid: "user id" (int)
mobile: "users mobile number" (int)
transaction: "transaction id" (int)
sms: "message sent to user mobile" (text)
created_dt: "unix timestamp of the transaction"
除了對_id索引(默認創建的),我們在移動和交易字段定義單獨的索引。
然而,下面的查詢需要60到120秒之間的任何地方完成:
{
mobile:<users mobile number>
}
我的MongoDB使用RockMongo訪問。 MongoDB在16GB RAM的服務器上託管。該服務器上近8GB的RAM是免費的。
這是什麼我在這裏做錯了?
更新:
的輸出解釋:mongostat的
{
"cursor" : "BasicCursor",
"nscanned" : 37145516,
"nscannedObjects" : 37145516,
"n" : 37145516,
"millis" : 296040,
"nYields" : 1343,
"nChunkSkips" : 0,
"isMultiKey" : false,
"indexOnly" : false,
"indexBounds" : {
}
}
輸出在
insert query update delete getmore command flushes mapped vsize res faults locked % idx miss % qr|qw ar|aw netIn netOut conn time
13 2 0 0 0 1 0 168g 336g 6.86g 1 1 0 0|0 1|0 21k 1k 19 11:30:04
16 0 0 0 0 1 0 168g 336g 6.88g 0 0.1 0 0|0 1|0 21k 1k 19 11:30:05
14 0 0 0 0 1 0 168g 336g 6.86g 0 0 0 0|0 1|0 29k 1k 19 11:30:06
10 0 0 0 0 1 0 168g 336g 6.86g 0 0 0 0|0 1|0 19k 1k 19 11:30:07
16 0 0 0 0 1 0 168g 336g 6.88g 0 0.1 0 0|0 1|0 21k 1k 19 11:30:08
9 0 0 0 0 1 0 168g 336g 6.89g 0 0 0 0|0 1|0 13k 1k 19 11:30:09
19 0 0 0 0 1 0 168g 336g 6.89g 0 0 0 0|0 1|0 27k 1k 19 11:30:10
12 0 0 0 0 1 0 168g 336g 6.89g 1 1.2 0 0|0 1|0 24k 1k 19 11:30:11
17 0 0 0 0 1 0 168g 336g 6.89g 1 1.7 0 0|0 1|0 31k 1k 19 11:30:12
15 0 0 0 0 1 0 168g 336g 6.89g 0 0 0 0|0 1|0 19k 1k 19 11:30:13
更新2查詢時間:
直到最近,我們用在同一個MongoDB服務器中存儲另一個約13億個文檔的集合。此集合現在已被刪除(刪除)。這可以解釋上面mongostat輸出中的mapped/vsize列。
服務器還存儲6個頻繁插入的其他集合。目前總存儲容量約爲35GB。
更新3:收集定義
指標。使用RockMongo創建。
[
{
"v" : 1,
"key" : {
"_id" : 1
},
"ns" : "mymongodb.transaction_sms_details",
"name" : "_id_"
},
{
"v" : 1,
"key" : {
"_transaction_mobile_" : 1
},
"ns" : "mymongodb.transaction_sms_details",
"background" : 1,
"name" : "mobile"
},
{
"v" : 1,
"key" : {
"_transaction_transaction_" : 1
},
"ns" : "mymongodb.transaction_sms_details",
"background" : 1,
"name" : "transaction"
}
]
你是否索引了移動領域? http://www.mongodb.org/display/DOCS/Indexes – sics
這個問題說他們做了(三個_id,移動和交易索引)。 – Thilo
每個手機號碼返回多少個文件? – Thilo