{"id":1318,"date":"2015-10-13T17:49:38","date_gmt":"2015-10-13T09:49:38","guid":{"rendered":"http:\/\/www.strongd.net\/?p=1318"},"modified":"2015-10-13T17:49:38","modified_gmt":"2015-10-13T09:49:38","slug":"5-steps-to-take-care-of-your-mongodb-performance","status":"publish","type":"post","link":"https:\/\/www.strongd.net\/?p=1318","title":{"rendered":"5 Steps to Take Care of Your MongoDB Performance"},"content":{"rendered":"<p>Do you face some performance issues in your MongoDB setup?<\/p>\n<p>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).<\/p>\n<h2>Step 1: Enable Slow Queries<\/h2>\n<p>Get intelligence about your system\u00a0behavior\u00a0and performance bottlenecks. Usually there is a high\u00a0correlation between the slow queries and your performance bottleneck, so use the following method to enable your system profiling collection:<\/p>\n<div class=\"CodeMirror cm-s-default\">\n<div class=\"CodeMirror-scroll\">\n<div class=\"CodeMirror-sizer\">\n<div>\n<div class=\"CodeMirror-lines\">\n<div>\n<div class=\"CodeMirror-code\">\n<div>\n<div class=\"CodeMirror-gutter-wrapper\"><\/div>\n<pre><span class=\"cm-variable\">db<\/span>.<span class=\"cm-variable\">setProfilingLevel<\/span>(<span class=\"cm-number\">1<\/span>, <span class=\"cm-number\">100<\/span>);<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"CodeMirror-gutters\"><\/div>\n<\/div>\n<\/div>\n<h2>Step 2: Use Explain<\/h2>\n<p>Explore the problematic queries using explain. You can also use <a href=\"https:\/\/github.com\/rueckstiess\/mtools\">mtools<\/a> to analyze the logged queries to find high frequent ones.<\/p>\n<h2>Step 3: Create Indexes<\/h2>\n<p>Your analysis should result with new indexes in order to improve the queries<\/p>\n<p>Don&#8217;t forget to use\u00a0<a href=\"http:\/\/docs.mongodb.org\/master\/tutorial\/build-indexes-in-the-background\/\">index buildup in the background<\/a>\u00a0to avoid collections locking and system downtime.<\/p>\n<h2>Step 4: Use\u00a0<a href=\"http:\/\/docs.mongodb.org\/manual\/core\/index-sparse\/\">Sparse Indexes<\/a>\u00a0to Reduce the Size of the Indexes<\/h2>\n<p>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.<\/p>\n<h2>Step 5: Use Secondary Preferred to Offload Queries to Slaves<\/h2>\n<p>You probably have a replica set and it&#8217;s waste of resources not using your slaves for read queries (especially for reporting and search operations).<\/p>\n<p>By changing your connection string to secondary\u00a0preferred, your application will try to run read queries on the slaves before doing that on your master.<\/p>\n<h2>Bottom Line<\/h2>\n<p>Using these simple methods, you can gain time and space before hitting a wall.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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\u00a0behavior\u00a0and performance bottlenecks. Usually there is a high\u00a0correlation between the &hellip; <a href=\"https:\/\/www.strongd.net\/?p=1318\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">5 Steps to Take Care of Your MongoDB Performance<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24,6,20],"tags":[],"class_list":["post-1318","post","type-post","status-publish","format-standard","hentry","category-android","category-linux","category-20"],"_links":{"self":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts\/1318","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1318"}],"version-history":[{"count":1,"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts\/1318\/revisions"}],"predecessor-version":[{"id":1319,"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts\/1318\/revisions\/1319"}],"wp:attachment":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1318"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1318"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1318"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}