Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Remember the solution to the problem that MongoDB CPU soared to 99%

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

The company adjusted its business and transferred some data from Redis to MongoDB. The business was normal in the test environment. After the production environment was launched, it was found that MongoDB's service directly occupied CPU. After analyzing with the students who developed it and referring to similar problems on Baidu, the final reason was: index was not used.

The solution is simple: create an index for the corresponding key field.

The reference commands are as follows:

>use Data; #Enter database Data, pay attention to case sensitivity;

>db.stats(); #View database status;

>db.getCollectionNames(); #View all table names;

>db.dynamic.find().limit(5); #View the first 5 entries of the dynamic table;

>db.dynamic.find().count(); #count how much data dynamic table has;

>db.dynamic.getIndexes(); #Query the indexes of table dynamic

#New index: index dynamic's score field backgroud

>db.dynamic.ensureIndex({score:1} , {backgroud:true});

#Status view: 20 seconds, updated once per second

mongostat -h 80.81.2.3 -p 27017 --rowcount 20 1

At first, the fields of index creation were not accurately identified, and the effect was not obvious. Later, after index creation for key fields, CPU utilization dropped precipitously.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report