MongoDB has been the most popular NoSQL, and according to Db-engines ranking the latest ranking, now MongoDB has defeated PostgreSQL leaped to the fourth place in the database ranking, after Oracle, MySQL and Microsoft SQ L Server, this article summarizes how to MongoDB performance tuning.
Have you ever encountered performance problems when using MongoDB? Here is a summary of the MongoDB performance optimization of the five steps, hope to be helpful.
First step: Find the slow statement
Generally speaking, query statements are too slow and performance problem bottlenecks have a direct relationship, so you can use MongoDB performance analysis tools to find these slow statements:
Db.setprofilinglevel (1, 100);
Step Two: Use explain analysis
These slow statements are diagnosed by using explain. In addition, you can mtools to analyze the log.
Step three: Create an index
After analysis, you need to create a new index to improve the performance of the query. Don't forget that in mondodb you can create indexes in the background to avoid collections locks and system crashes.
Step Fourth: Use sparse indexes to reduce space consumption
If you use sparse documents, and you use the keyword $exists, you can use sparse indexes to reduce the performance of space occupancy elevation queries.
Fifth step: Read and write separation
If read and write are in the main node, from the node has been in the vacant state, this is a waste. This can be done from the node for a report or search, so it is set to secondarypreferred in the connection string.
Small summary
Although these methods can play a role, the main goal is to buy a little time for the improvement of the architecture.
Well, the above mentioned is the entire content of this article, I hope that we learn MongoDB performance optimization has helped.