Business adjustment, a part of the data from Redis to MongoDB, the business in the test environment, the production environment on the line after the discovery of the pressure MongoDB services directly to the CPU full, and the development of the classmate analysis of a bit also refer to Baidu on similar issues, Last location reason: Index not used.
The workaround is simple: Create an index of the corresponding key field.
The reference commands are as follows:
>use Data; #进入数据库Data, pay attention to case sensitivity;
>db.stats (); #查看数据库的状态;
>db.getcollectionnames (); #查看所有表名;
>db.dynamic.find (). Limit (5); #查看dynamic表的前5条数据;
>db.dynamic.find (). Count (); #统计dynamic表总共有多少数据;
>db.dynamic.getIndexes (); #查询表dynamic的索引
#新建索引: Score fields for dynamic are indexed in backgroud manner
> db.dynamic.ensureIndex ({score:1}, {backgroud:true});
#状态查看: 20 seconds, updated once per second
mongostat -h 80.81.2.3 -p 27017 --rowcount 20 1
The field that started creating the index is not accurate, the effect is not obvious, and then the CPU usage is dropped after the index of the key field is created.
This article is from the "drag tail in the painting" blog, please be sure to keep this source http://cangzihu.blog.51cto.com/6671848/1904765
Remember once MongoDB CPU soared to 99% problem solved