请教大神们? node-mongodb-native 模块本地连接mongodb查询有时候耗时800+ ms,数据量30条,何解???
代码如下:
var startTime = new Date().getTime(); client.acquire(function (err, db) { if (err) { log.error(“Connected wrong to server”); } else { var collection = db.collection(table); log.info("aggregateDocuments data: ", JSON.stringify(condition)); collection.aggregate(condition, function (err, result) { var end = new Date().getTime(); console.error("===mongo=====>>>>"+(end-startTime)); self.returnResult(err, result, cb); }); } client.release(db); });
@haozxuan condition是: [{"$match":{"status":"1","is_del":"0","class_id":{"$in":[“1”]},"school_id":"1","$or":[{"create_id":"1"},{"receivers":{"$in":[“1”]}},{"is_school":1},{"is_class":1}]}},{"$project":{"type":1,"content":1,"medias":1,"create_id":1,"create_name":1,"create_time":1,"update_time":1,"create_head_img":1,"praisesOrReceipt":1,"comments":1}},{"$limit":10},{"$sort":{"create_time":-1}}] 索引是:create_time. 我就没整明白的是,数据才30条,siege -c 1000 ,有时候10ms都不要就出结果,有时候1000+ms才出结果.机器内存cpu都很富裕.
@haozxuan 其实一条简单查询也很慢的,siege -c 1000 ,也一样,有时候10ms都不要就出结果,有时候1000+ms才出结果.
condition: [{"$match":{"status":"1","is_del":"0"}},{"$project":{"type":1,"content":1,"medias":1,"create_id":1,"create_name":1,"create_time":1,"update_time":1,"create_head_img":1,"praisesOrReceipt":1,"comments":1}},{"$limit":10},{"$sort":{"create_time":-1}}]