search

Home  >  Q&A  >  body text

关于mongodb的耗时问题

查询代码:

console.time('计时器1')
collection.count({}, function(err, count) {
        collection.find({}, {
            limit: num,
            skip: (data.page - 1) * num
        }).sort({
            time: -1
        }).toArray(function(err, list) {
            mongoDb.close();
            var page = {}
            page["count"] = count
            page["limitNum"] = num
            callback(null, list, page)
            console.timeEnd('计时器1')
        })
    });

上图,这是我再window下监控到的mongo耗时时间

下图是我再linux下面的耗时时间

为什么同样的查询代码会相差差不多3倍之大?我的数据量就只有67条而已

过去多啦不再A梦过去多啦不再A梦2757 days ago625

reply all(3)I'll reply

  • 阿神

    阿神2017-05-02 09:26:33

    I found the reason, it’s because the account password is set. I see that every time I request mongo, it will verify the account password, which causes the time to take a long time. If I remove it, it drops to about 30ms

    reply
    0
  • 给我你的怀抱

    给我你的怀抱2017-05-02 09:26:33

    Is it possible to consider printing out the execution plans when querying MongoDB on two different OSs, and compare the execution plans on both sides?

    reply
    0
  • 过去多啦不再A梦

    过去多啦不再A梦2017-05-02 09:26:33

    Is your Linux system 32-bit or 64-bit?

    reply
    0
  • Cancelreply