MongoDB constantly high cpu usage

前端 未结 2 1238
再見小時候
再見小時候 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.

    0 讨论(0)
  • 2021-02-04 01:27

    There is a function called db.currentOp() which lists the currently running queries with very detailed information, it also includes the duration they have been running (secs_running).

    You can then use the currentOp.opid with db.killOp() to kill that query/operation.

    If db.currentOp() doesn't return any results, because there is no query which went havoc, then there's also db.setProfilingLevel() which will enable profiling by storing queries into the "local" database. Here's a "Tutorial" which is from the "M102: MongoDB for DBAs" Course.

    Further information can also be found in this detailed article "Troubleshooting MongoDB 100% CPU load and slow queries" from Igor Khomenko.

    0 讨论(0)
提交回复
热议问题