title: Node.js, cluster, express, apache ab and mongodb
body: <p>I'm new to mongo and have a few performance tests setup with Node.js (v0.4.12), cluster (Learnboost v0.7.7) and express (v2.5.9).  I'm trying to connect to mongo and do a simple performance test with apache ab.  I've set this up with MySql and it works flawlessly, but when I try to do the same test with mongo I don't get the results I expect.</p>
  
  <p>With MySql, I send 10,000 requests to the node.js cluster (8 cores) and I get 10,000 rows inserted into the db.  No issues.  But, when I do the same thing with mongo, I only get around 4,500-4,900.  I've tried mongoskin, mongo-lite, node-mongodb-native and all have exactly the same result.  </p>
  
  <p>I thought maybe it was the pool size, so I increased/decreased that.  Nothing.  No errors or exceptions.  I'm at a loss...</p>
  
  <p>Any help would be appreciated.  </p>
  
  <p>Thanks.</p>
  
  <p>The code for the test is below;</p>
  
  <h2>app.js</h2>
  
  <pre><code>var mongoLite = require('mongo-lite');
  var express   = require('express');
  
  var count  = 1;
  var config = {
  host    : 'localhost', 
  user    : USER,
  pass    : PASSWORD,
  port    : '27017',
  db      : 'test',
  options : 'poolSize=10'
  };
  
  var configUrl = 'mongodb://'    +
                config.user + ':' + 
                config.pass + '@' + 
                config.host + ':' + 
                config.port + '/' +
                config.db;
  
  
  var mongo   = mongoLite.connect(configUrl);
  var server  = express.createServer();
  
  server.get('/test/:id', function (req, res) {               
  mongo.collection('test_' + req.params.id).insert({_id: count++}, function(err, doc){
      if (err)
          throw err;
  });
  res.end('inserted');
  });
  
  module.exports = server; 
  </code></pre>
  
  <h2>server.js</h2>
  
  <pre><code>var cluster = require('cluster');
  
  cluster('./app')
      .use(cluster.reload())
      .use(cluster.logger('logs'))
      .use(cluster.stats())
      .use(cluster.pidfiles('pids'))
      .use(cluster.cli())
      .use(cluster.repl(8888))
      .listen(81);
  </code></pre>