5 Steps to Take Care of Your MongoDB Performance

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.