我有一个查询需要很长时间才能完成。 我喜欢做一些性能测试,但是在我检查一次(目前需要大约 30 秒)之后,查询开始运行得更快(< 1 秒)。 我认为它必须与 mongodb 缓存有关。 有没有办法禁用 mongodb 的缓存或者我可以检查性能的其他方法?
我正在使用托管在 mongohq 中的 mongodb。使用 Ruby on Rails 3 编程。 解释如下:
{"cursor"=>"BtreeCursor start_-1", "nscanned"=>5276, "nscannedObjects"=>5276, "n"=>25, "millis"=>3264, "nYields"=>0, "nChunkSkips"=>0, "isMultiKey"=>false, "indexOnly"=>false, "indexBounds"=>{"start"=>[[{"$maxElement"=>1}, {"$minElement"=>1}]]}, "allPlans"=>[{"cursor"=>"BtreeCursor attendees_count_-1", "indexBounds"=>{"attendees_count"=>[[1.7976931348623157e+308, 1]]}}, {"cursor"=>"BtreeCursor images_count_-1", "indexBounds"=>{"images_count"=>[[1.7976931348623157e+308, 2]]}}, {"cursor"=>"BtreeCursor start_-1", "indexBounds"=>{"start"=>[[{"$maxElement"=>1}, {"$minElement"=>1}]]}}, {"cursor"=>"BtreeCursor start_-1_end_-1", "indexBounds"=>{"start"=>[[{"$maxElement"=>1}, {"$minElement"=>1}]], "end"=>[[{"$maxElement"=>1}, {"$minElement"=>1}]]}}, {"cursor"=>"BtreeCursor attendees._id_1 multi", "indexBounds"=>{"attendees._id"=>[[BSON::ObjectId('4f0b621e94bb688563000007'),BSON::ObjectId('4f0b621e94bb688563000007')], [BSON::ObjectId('4f0b647d5a8c00acde05236f'), BSON::ObjectId('4f0b647d5a8c00acde05236f')], [BSON::ObjectId('4f0b647d5a8c00acde052370'), BSON::ObjectId('4f0b647d5a8c00acde052370')], [BSON::ObjectId('4f0b647d5a8c00acde052371'), BSON::ObjectId('4f0b647d5a8c00acde052371')], [BSON::ObjectId('4f0b647d5a8c00acde052372'), BSON::ObjectId('4f0b647d5a8c00acde052372')], [BSON::ObjectId('4f0b647d5a8c00acde052373') ... (lots of Object IDs)]]}}}
请注意,我不得不截断一些解释,因为它太长了。 有“很多对象 ID”的地方有很多对象 ID(~400)。
谢谢大家
最佳答案
我猜你不能阻止 Mongo 准备查询计划(这就是 mongo 的工作方式)。 因此,在查询统计信息之前.. 1.清除所有集合的计划缓存
>db.colllction_name.getPlanCache().clear()
- 用 Profiler 记录慢查询(参见 mongo 文档),
- 处理查询以优化它,
- 再次清空缓存,再次检查查询性能。
关于mongodb - 如何在没有缓存的情况下检查 mongodb 查询性能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9362831/