0

I'm measuring the performance difference of insert between a connection with safe: true and another with safe: false. However, changing the safe variable does not seem to affect the performance at all.

var dbURI = 'mongodb://' + 'user' + ':' + 'password' + '@' + '11.111.111.111' + ':' + '3000' + '/' + 'test';
var db = mongo.db(dbURI, {safe: true/false});

var queryArray = [];

for (var i = 0; i < 200000; i++) {
    queryArray.push({random: i})
}

db.collection('insertTest1').insert(queryArray, function(err, result) {
    respond ('it is done');
});

Even when I switch the safe variable around, the average execution time always comes out to be around 25 seconds. I was under the impression setting the safe variable to false would drastically improve performance.

Is this not how you change the safe variable in mongoskin? Or is this an expected result?

Stennie
  • 63,885
  • 14
  • 149
  • 175
jeebface
  • 841
  • 1
  • 12
  • 29
  • When I test this in the mongo shell, it takes way less than 25 seconds, perhaps about 5 seconds, with the default (safe) write concern. I think the difference between the write concerns is negligible here because there is a slow step that is totally overwhelming the difference between the write concerns because it takes so much longer. Perhaps network latency? – wdberkeley Sep 03 '14 at 16:32
  • What version of MongoDB do you have? I recently learned that MongoDB 2.6+ has different insertion behavior by default and the slow insertion performance can be attributed to the change. – jeebface Sep 03 '14 at 19:05
  • I'm testing on the most recent version, 2.6.4. – wdberkeley Sep 03 '14 at 19:55
  • I find it hard to believe that it's network latency because when I run a very similar query on MySQL on the same AWS instance I get around 3.5 seconds. When I use bulk insertion with MongoDB the execution time was cut down to around 8~9 seconds. – jeebface Sep 03 '14 at 21:12

0 Answers0