title: Slow Meteor MongoDB Subscription
body: <p><strong>Problem:</strong> </p>
  
  <p>Slow MongoDB subscription inside Meteor (on average 500ms), CPU usage stays at 100% after starting meteor. I suspect it is a permission or settings issue. </p>
  
  <p><strong>Details:</strong> </p>
  
  <p>1) Setup: CentOS 6.6, MongoDB 3.0 with Oplog tailing enabled, fast CPU, lots of RAM. Complication, any command beginning with SUDO incurrs 10-30s delay. </p>
  
  <p>2) Serverside publication: </p>
  
  <pre><code>Meteor.publish('price', function() {
    return priceCollection.find({"type":"Price","Name":"item1"}, {sort: {"date": -1}, fields:{"type": 1, "Name": 1, "date": 1, "value": 1}, limit: 2});
  });
  </code></pre>
  
  <p>3) Clientside subscription via Iron Router using Subscription Manager </p>
  
  <pre><code>waitOn: function() {
        return [permanentSubs.subscribe("price")];
      }
  </code></pre>
  
  <p>4) Remote MongoDB performance: </p>
  
  <pre><code>rs0:PRIMARY&gt; db.priceCollection.find({"type":"Price", "Name":"item1"}, {"type":1, "Name":1, "date":1, "value":1}).sort({"date":-1}).limit(2).explain("executionStats")
  </code></pre>
  
  <p>The proper index is used and execution time is on average between 0-10ms. </p>
  
  <p>5) Meteor Minimongo performance: no performance issues after subscription is done, 2 documents return without any delay using Chrome browser console. </p>
  
  <p>6) Need to wait for one second before page renders. Using Kadira shows publication time ranges between 400ms-600ms. </p>
  
  <p>7) Running Kadira CPU profiler: 53% package:ejson, 25% package:underscore, the rest: &lt;1%. </p>
  
  <p>8) Kadira shows no server side errors and subscription errors.</p>
  
  <p><strong>Want answers to</strong></p>
  
  <p>1) Where to begin hunting down the root cause of the slow down? </p>
  
  <p>2) Is there any other debugging tools available to breakdown subscription process to help debug subscription performance issue. </p>
  
  <p>If more information is required, please leave comments. </p>