MongoDB high CPU usage – A real-time fix for you

Table of Contents

It’s really annoying, when the server slows down without any apparent reason.

Often MongoDB high CPU usage can be a reason for slowness. And, this slowness can be due to bad MongoDB server optimization.

That’s why we often get requests from our customers to fix MongoDB high CPU usage as part of our Server Management Services.

Today, we’ll see how our Support Engineers fixed MongoDB high CPU usage for a customer and fixed related errors.



Reasons for MongoDB high CPU usage?

In general, CPU usage indicates the overall efficiency of any server. When there is a heavy CPU usage by MongoDB, it can often result in tardy website applications.

The performance will be high when the  MongoDB use less CPU. However, it will create a very slow and undesirable user experience within the online applications when MongoDB uses high CPU.

There are several reasons that slow down the MongoDB server. It includes:

1. Wrong MongoDB server settings

Often bad MongoDB server settings cause high CPU usage which reduces the server performance.

For example, we saw that one of our customers had set to log every connection made to the server in the log file. When writing every connection to the log file, it will utilize the processor for its Input/Output operations. Therefore, it used a major part of CPU resources. Furthermore, this can affect other write or read tasks in the server.

Additionally, this would make the MongoDB log file grow up to a large size. And, as MongoDB server processes these big log files, eventually all  database tasks will get delayed.

2. System Parameters

From our experience in managing servers, our Dedicated Engineers often see that network stack variables and file system parameters also affect the working of MongoDB.

In addition to tweaking in MongoDB server configuration, setting the ideal values for the following system parameters also improve the MongoDB performance.

  1. Linux Ulimit
  2. Virtual Memory
  3. Transparent HugePages
  4. Block Device :
  5. IO Scheduler and Read-Ahead
  6. Filesystem and Options
  7. Network Stack

3. Bad database queries

Sometimes, the database takes too long to perform and finish the queries. These slow queries can occur if the database doesn’t have proper DB indexes.

DB indexes help to perform faster database queries in MongoDB. Without indexes, it uses a Collection Scan method to determine the documents that match the query statement. And, when you have a lot of documents in your collection, it can take a while to process the query.

How we fixed MongoDB high CPU usage

Till now, we saw the top reasons that would affect MongoDB performance on a server. Now, it’s time to check the solutions for the same.

Let’s have look on how our Support Engineers recently solved the CPU usage problem.

Recently, one of the customers had an issue with server performance. His WHM server was very slow and provided undesirable user experience within their website applications.

On checking, our Support Engineers found that his MongoDB used high CPU resources and that slowed his server. The exact process usage on his server appeared as below. MongoDB was using a CPU% of 138.24.

So, we took the following steps to solve the issue.

1. Initially, we connected to the server as root user.

2. We then checked the CPU usage and load on the server. The result showed 200% CPU usage and looked like:

3. On further checking the details, we found that the MongoDB log file size had reached 105GB on the server. This customer had set to log all MongoDB queries.

4. Then, after checking with the customer, we backed up the log file and cleared it and checked the CPU usage by using the command  top -c . The CPU usage reduced dramatically as below.

5. We checked the log file and could find that every connection made to the server was being logged in the log file. That increased the CPU usage so we suggested to the customer to logging only the error messages in the log file of the database server.

Additionally, we tweaked the system parameters on the server for the optimum MongoDB performance too.

That fixed the issue and gave optimum server performance.

[Is your MongoDB server causing high CPU usage? We’ll fix it for you.]


In short, often bad database queries and wrong MongoDB server settings result in MongoDB high CPU usage on the server. Today, we saw how our Support Engineers fixed high CPU usage problem for a customer.

Leave a Comment

Your email address will not be published. Required fields are marked *

Social Share


Cheapest Web Hosting

Fasters Web Hosting Promo
Scroll to Top

Launch your Website at RS599

Create a professional website yourself with our domain hosting combo. Get Extra benefits at this Year end Sale with 10% OFF and Enjoy Amazing Deels on Shared Hosting!

Starting at Only RS599/Year

Year End Sale


Use Code STARTBIZ at Checkout.

Create an earning opportunity with A Web Hosting Business

Become reseller and start reselling domains, web hosting, ssl certificates and More.

45% OFF

Starting at RS399/Month


Use coupon: at the checkout.