5 Steps to Take Care of Your MongoDB Performance
5 Steps to Take Care of Your MongoDB Performance
Improve the performance of your MongoDB database with a few quick tips.
Join the DZone community and get the full member experience.
Join For FreeRavenDB vs MongoDB: Which is Better? This White Paper compares the two leading NoSQL Document Databases on 9 features to find out which is the best solution for your next project.
Do you face some performance issues in your MongoDB setup?
In this case follow these steps to provide some first aid to your system and gain some space for a long term architecture (such as Sharding).
Step 1: Enable Slow Queries
Get intelligence about your system behavior and performance bottlenecks. Usually there is a high correlation between the slow queries and your performance bottleneck, so use the following method to enable your system profiling collection:
db.setProfilingLevel(1, 100);
Step 2: Use Explain
Explore the problematic queries using explain. You can also use mtools to analyze the logged queries to find high frequent ones.
Step 3: Create Indexes
Your analysis should result with new indexes in order to improve the queries
Don't forget to use index buildup in the background to avoid collections locking and system downtime.
Step 4: Use Sparse Indexes to Reduce the Size of the Indexes
If you use sparse documents, and heavily using the $exists key words in your queries, using sparse indexes (that includes only documents that includes your field) can minimize your index size the boost your query performance.
Step 5: Use Secondary Preferred to Offload Queries to Slaves
You probably have a replica set and it's waste of resources not using your slaves for read queries (especially for reporting and search operations).
By changing your connection string to secondary preferred, your application will try to run read queries on the slaves before doing that on your master.
Bottom Line
Using these simple methods, you can gain time and space before hitting a wall.
Aggregations provide vital intelligence to the success of a business. Crush the challenge of providing real time aggregations for daily, weekly, and monthly totals without having to tie up your servers.
Published at DZone with permission of Moshe Kaplan , DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
{{ parent.title || parent.header.title}}
{{ parent.tldr }}
{{ parent.linkDescription }}
{{ parent.urlSource.name }}