Skip to content

Instantly share code, notes, and snippets.

@andreaseger
Created June 6, 2011 10:30
Show Gist options
  • Save andreaseger/1010049 to your computer and use it in GitHub Desktop.
Save andreaseger/1010049 to your computer and use it in GitHub Desktop.
mongodb growth test
function randomString(length) {
var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
var string_length = length;
var randomstring = '';
for (var i=0; i<string_length; i++) {
var rnum = Math.floor(Math.random() * chars.length);
randomstring += chars.substring(rnum,rnum+1);
}
return randomstring;
}
function payload(){
return randomString(Math.floor(Math.random() * 100));
}
function run(){
db.test.createIndex({i:1});
for (n=0;n<20;n=n+1)
{
for (v=0;v<100000;v=v+1)
{
p = payload();
db.test.insert({i:v, payload:p});
}
db.test.remove({});
s = db.test.stats().toSource()
v = db.test.validate().toSource()
print(n + ": size/storage: " + s.match(/size:(\d*)/)[1] + "/" + s.match(/storageSize:(\d*)/)[1] + " | " + v.match(/deleted: n: \d* size: \d*/))
}
print('droping the database')
db.dropDatabase();
};
run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment