MongoDB constantly high cpu usage

前端 未结 2 1239
再見小時候
再見小時候 2021-02-04 00:58

According to docker container statistics, my mongo database consumes constantly between 250 and 350% cpu. That\'s pretty impressive since it\'s a single core system :P

T

2条回答
  •  被撕碎了的回忆
    2021-02-04 01:19

    The first and more important thing that you need to do is check your kind of queries, for example, in my case I had the same problem and when I checked my logs tail -f /var/log/mongodb/mongod.log (You can configure this logs in /etc/mongod.conf) I only saw the simple queries like db.brands.find({"field":"value"}) but I checked my indexes in "brands" collections and this field on queries was not indexed (db.brands.getIndexes()). The only thing that I did is index this field db.brands.ensureIndex({name:1},{unique:true}). Of course make sure if your field is unique because in this example I put as a unique. After that my CPU changed from 100% to 20%.

    So I am not saying that is your problem but could be, check your queries before doing some bigger things.

提交回复
热议问题