Skip to content

Instantly share code, notes, and snippets.

@AlekSi
Created August 18, 2011 13:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlekSi/1154108 to your computer and use it in GitHub Desktop.
Save AlekSi/1154108 to your computer and use it in GitHub Desktop.
MongoDB benchmark for Graylog2
count = 10000
size = 100 // megabytes
hosts = ['host1', 'host2', 'host3', 'host4', 'host5']
facilities = ['Server', 'Client', 'Proxy']
chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz '.split('');
speed = 1500.0; // messages per second
start = new Date().getTime() - 24*60*60*1000;
function random(elements) {
return elements[Math.floor(Math.random() * elements.length)];
}
function message() {
var str = '';
for (var i=0; i < 100; i++) {
str += random(chars);
};
return str;
}
db.messages.drop()
db.createCollection('messages', {capped: true, size: size * 1024 * 1024})
for (var i = 0; i < count; i++) {
hash = {};
hash.created_at = (start + i / speed * 1000.0) / 1000.0;
hash.host = random(hosts);
hash.facility = random(facilities);
hash.level = random([1,2,3,4,5,6]);
hash.message = message();
db.messages.save(hash);
}
db.messages.find().sort({$natural: 1}).limit(1).forEach(function(x) { printjson(x); })
db.messages.find().sort({$natural: -1}).limit(1).forEach(function(x) { printjson(x); })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment