29

Perhaps I have misconfigured MongoDB somehow, but even under heavy load I don't see it using more than one core. For example, top is currently showing:

Tasks: 145 total,   1 running, 144 sleeping,   0 stopped,   0 zombie
Cpu0  :  0.0%us,  0.0%sy,  0.0%ni,100.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Cpu1  :  0.0%us,  0.0%sy,  0.0%ni,100.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Cpu2  :  0.0%us,  0.0%sy,  0.0%ni,100.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Cpu3  :100.0%us,  0.0%sy,  0.0%ni,  0.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:  41182768k total, 40987476k used,   195292k free,   109956k buffers
Swap:  2097144k total,  1740288k used,   356856k free, 28437928k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                                         
16297 mongod    15   0  521g  18g  18g S 99.8 47.2   2929:32 mongod                                                                           
    1 root      15   0 10372  256  224 S  0.0  0.0   0:03.39 init      

Is there something I can do to get Mongo to use the other cores more effectively? If it's relevant, I currently have a big M/R running which seems to have put a lot of read queries in "waiting" mode.

1
  • Just an update/clarification. My original question was about Map/Reduce, but you can use the Aggregation Pipeline instead this uses CPUs much more efficiently. May 15, 2019 at 10:17

1 Answer 1

38

MongoDB can saturate all cores on a multi-core machine for read operations, but for write operations and map-reduce MongoDB can only utilize a single core per mongod process.

The limitation for single-core MapReduce is due to the Javascript interpreter that MongoDB utilizes. This is something that is supposed to be fixed in the future but in the interim you can use Hadoop to execute the MapReduce and store the result set in your MongoDB database.

Another option which has seen mixed results is to run a single mongod process for every core on the instance this will not increase performance for a single database unless they are configured to run in a sharded setup.

9

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.