Last active
December 21, 2015 03:09
-
-
Save fergiemcdowall/6239924 to your computer and use it in GitHub Desktop.
A gist that stress tests levelUP by inserting lots of batch files containing JSON. This can be configured to create a "memory leak" in levelUP.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//fergusmcdowall@gmail.com | |
//A very simple stress test for levelUP | |
//make lots of LorumIpsum json files, put them into batches, and then | |
//cram as many of them as possible into LevelUP | |
//At the time of writing (15 aug 2013) this will create a memory leak | |
//adjust size of batches here | |
var totalBatchFiles = 300; | |
var totalDocsPerBatchFile = 100; | |
var totalFieldsPerDoc = 10; | |
var totalSentencesPerField = 50; | |
var loremIpsum = require('lorem-ipsum'); | |
var levelup = require('levelup'); | |
var db = levelup('./db', | |
{valueEncoding: 'json'}) | |
for (var i = 0; i < totalBatchFiles; i++) { | |
var batch = []; | |
for (var j = 0; j < totalDocsPerBatchFile; j++) { | |
var value = {}; | |
var key = i + '~' + j; | |
for (var k = 0; k < totalFieldsPerDoc; k++) { | |
var fieldText = loremIpsum({ | |
count: totalSentencesPerField, | |
units: 'sentences', | |
sentenceLowerBound: 5, | |
sentenceUpperBound: 15, | |
paragraphLowerBound: 3, | |
paragraphUpperBound: 7, | |
format: 'plain', | |
random: Math.random | |
}); | |
var fieldIndex = loremIpsum({ | |
count: 1, | |
units: 'words', | |
format: 'plain', | |
random: Math.random | |
}); | |
value[fieldIndex] = fieldText; | |
} | |
batch.push({ | |
type: 'put', | |
key: key, | |
value: value}); | |
console.log(key); | |
} | |
insertBatch(i, batch); | |
} | |
function insertBatch(id, thisBatch) { | |
console.log('queueing batch ' + id); | |
db.batch(thisBatch, function (err) { | |
console.log('inserted batch ' + id); | |
if (err) return console.log('Ooops!', err); | |
return; | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "LevelUpStressTest", | |
"description": "a module that creates pretent JSON files an inserts them into levelUP", | |
"version": "0.1.1", | |
"engines": { | |
"node": ">=0.4.10" | |
}, | |
"dependencies": { | |
"lorem-ipsum": "*", | |
"levelup": "*", | |
"leveldown": "*" | |
}, | |
"author": "Fergus McDowall <fergusmcdowall@gmail.com>" | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
my version with some breathing space for V8, in the above version there is absolutely no room for the callbacks to get back in to the event loop.