Skip to content

Instantly share code, notes, and snippets.

@rickbergfalk
Created August 22, 2013 16:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rickbergfalk/6309444 to your computer and use it in GitHub Desktop.
Save rickbergfalk/6309444 to your computer and use it in GitHub Desktop.
A quick little stress test for nodejs level module. On windows this eventually comes to a crawl, and dies with a out-of-memory exception.
var levelup = require('level');
var db = levelup('./leakydb', {valueEncoding: 'json'});
var BATCH_SIZE = 10000
var BATCH_STARTING_ITERATION = 1000; // start at a high number to make it a bit easier on leveldb puts (1001, 1010, 1100 is more sort friendly than 1, 10, 100)
var BATCH_END_ITERATION = 2000;
var batchIteration = BATCH_STARTING_ITERATION;
var putBatch = function () {
var ops = [];
for (var i = 0; i < BATCH_SIZE; i++) {
var d = new Date();
var key = "aKeyLabel~" + batchIteration + "~" + i + "~" + d;
var value = {
batchIteration: batchIteration,
i: i,
createdDate: new Date(),
someText: "I think level for windows leaks memory :("
};
ops.push({type: "put", key: key, value: value});
};
db.batch(ops, function (err) {
if (err) {
console.log(err);
} else {
var actualIteration = batchIteration - BATCH_STARTING_ITERATION;
var recordsPut = actualIteration * BATCH_SIZE;
console.log(recordsPut + " records put " + new Date());
batchIteration = batchIteration + 1;
if (batchIteration < BATCH_END_ITERATION) {
putBatch();
} else {
console.log('we made it!');
}
}
});
};
putBatch();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment