[Aliyun] Problem solved for MongoDB CPU Utilization over 90% in ECS
- Connect to MongoDB and Change Profiler

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
1will profile operations slower than the threshold.By default,
sampleRateis set to1.0, meaning all slow operations are profiled. WhensampleRateis set between 0 and 1, databases with profiling level1will only profile a randomly sampled percentage of slowoperations according tosampleRate.
*Reference : MongoDB Documentation
6. Everything looks great!! Close Profiler.
db.setProfilingLevel(0)