Mongo DB의 표준 Homebrew 설치 버전 2.4.6을 실행 중이며 'items'라는 컬렉션이있는 데이터베이스가 있습니다.이 데이터베이스에는 600k 개의 문서가 있습니다.MongoDB 집계 성능 이해
내가 항목의 수집에 대한 상위 5 개 브랜드를 찾을 수있는 다음과 같은 쿼리를 작성했습니다 :
db.items.aggregate([
{ $group: { _id: '$brand', size: { $sum: 1}}},
{ $sort: {"size": -1}},
{ $limit: 5}
])
내가 기대했던 결과를 반환하지만 솔직히하기를, 나는보다 완료하는 데 더 오래 걸립니다 이제까지 상상했을 것입니다. 여기
{
"op" : "command",
"ns" : "insights-development.$cmd",
"command" : {
"aggregate" : "items",
"pipeline" : [
{
"$group" : {
"_id" : "$brand",
"size" : {
"$sum" : 1
}
}
},
{
"$sort" : {
"size" : -1
}
},
{
"$limit" : 5
}
]
},
"ntoreturn" : 1,
"keyUpdates" : 0,
"numYield" : 3,
"lockStats" : {
"timeLockedMicros" : {
"r" : NumberLong(3581974),
"w" : NumberLong(0)
},
"timeAcquiringMicros" : {
"r" : NumberLong(1314151),
"w" : NumberLong(10)
}
},
"responseLength" : 267,
"millis" : 2275,
"ts" : ISODate("2013-11-23T18:16:33.886Z"),
"client" : "127.0.0.1",
"allUsers" : [ ],
"user" : ""
}
이
db.items.stats()
의 ouptut입니다 : 다음은 프로파일 데이터는
{
"sharded" : false,
"primary" : "a59aff30810b066bbe31d1fae79596af",
"ns" : "insights-development.items",
"count" : 640590,
"size" : 454491840,
"avgObjSize" : 709.4894394230319,
"storageSize" : 576061440,
"numExtents" : 14,
"nindexes" : 10,
"lastExtentSize" : 156225536,
"paddingFactor" : 1,
"systemFlags" : 1,
"userFlags" : 0,
"totalIndexSize" : 165923744,
"indexSizes" : {
"_id_" : 17889088,
"demographic_1" : 14741328,
"brand_1" : 17946320,
"retailer_1" : 18690336,
"color_1" : 15738800,
"style_1" : 18951968,
"classification_1" : 15019312,
"placement_1" : 19107312,
"state_1" : 12394816,
"gender_1" : 15444464
},
"ok" : 1
}
난이 집계가 너무 오래 걸리는 이유를 내가 바라고 누군가가 지적 할 수 MongoDB를 상당히 새로운 600K가 계산을 실행하는 Mongo 문서의 엄청난 수는 아니라고 생각하는 것처럼 내가 속도를 내기 위해 할 수있는 일이 있다면 무엇이든 할 수있다.
고유 한 몇 개의 브랜드가 있습니까? – WiredPrairie
@ WiredPrairie ~ 26k 독특한 브랜드. – TheDelChop
db.serverStatus는 그다지 유용하지 않습니다. db.items.stats()는 어떻습니까? –