11
AUG
AUG
A Very Simple Mongo Insert Speed Test
I ran the test below on my macbook pro — both database and app server running on the same machine. Result is about 19k inserts / second.
The collection being tested has one index on the _id field. In general, the more indexes present, the slower inserts will be. One question here is: will the insert rate slow down once the index is too large to fit in RAM? In general, the answer will be yes of course. However, when indexing on object ID, it may not slow down: the ID’s have a timestamp component which makes them increase over time, thus all inserts in the b-tree will occur near the right-hand edge. That “edge” of the tree will always fit in ram. (That said I did not run such a test -- YMMV.)
~/ed ./runLight.bash ed.js.Shell /tmp/test.js
...
i: 1000000 19666/sec
~/ed cat /tmp/test.js
// very simple speed test
db=connect("test");
t1 = db.collection2;
t1.ensureIndex({_id:ObjId()});
var start = new Date();
var i = 0;
for( var i = 0; i < 1000000; i++ ) {
t1.save( { i:i, z: "abaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
} );
if( i % 10000 == 0 ) {
print(i);
}
}
// make us wait until db has completed all work:
t1.findOne();
var now = new Date();
var persec = i / ((now-start+1)/1000);
print("i: " + i + " " + persec.toFixed() + "/sec");
Categories:
db

add a comment