Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoDB's runCommand is much slower than direct call

I have this two mongo commands, that in my opinion should lead to the same results:

for(var i=0;i<1000;i++){db.test.insert({a:1}); db.getLastError({j:1, w:1});};

for(var i=0;i<1000;i++){db.test.insert({a:1}); db.runCommand({getLastError:1, j:1, w:1});};

both commands perform inserts correctly, however, the second one is cca 100x times slower (500ms vs 45s). Does anybody know, why this is so? The difference is present only when {j:1} is set, so it's probably somehow related to some journaling issues?

like image 739
Tomas Kulich Avatar asked Nov 11 '22 16:11

Tomas Kulich


1 Answers

The second command is actually waiting for the journal commit whereas the first is not and hence the difference. When using the getLastError shell helper you cannot pass in the j option. It should be a number or string corresponding to the w parameter to the getlasterror database command as documented here.

like image 194
Sridhar Nanjundeswaran Avatar answered Nov 14 '22 23:11

Sridhar Nanjundeswaran