[Aliyun] Problem solved for MongoDB CPU Utilization over 90% in ECS

Hui Yi Chen
Sep 4, 2018 · 1 min read
  1. Connect to MongoDB and Change Profiler
*Reference : MongoDB Documentation
db.setProfilingLevel(2)

2. find out latest log from system.profile (latest 10 records)

db.system.profile.find().limit(10).sort( { ts : -1 } ).pretty()
or
//sort by insert timestamp
db.system.profile.find().sort({$natrual: -1}).limit(3)

3. find out the utilization of CPU: use COLLSCAN query collection will affect CPU utilization. Start to find out which query use COLLSCAN and check field “docsExamined”, it shows the utilization of CPU, a larger number means the high CPU usage.

4. Add Index: find out which collection need to add index due to a large dataset and frequently query.

5. Confirm CPU Usage getting low, and then set MongoDB Profiler to 1. Observing the status for a week.

db.setProfilingLevel(1,{slow:70, sampleRate:0.75})

By default, the slow operation threshold is 100 milliseconds. Databases with a profiling level of 1 will profile operations slower than the threshold.

By default, sampleRate is set to 1.0, meaning all slow operations are profiled. When sampleRate is set between 0 and 1, databases with profiling level 1 will only profile a randomly sampled percentage of slowoperations according to sampleRate.

*Reference : MongoDB Documentation

6. Everything looks great!! Close Profiler.

db.setProfilingLevel(0)
Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade