Skip to content

Instantly share code, notes, and snippets.

View kylegetson's full-sized avatar

Kyle Getson kylegetson

View GitHub Profile
@kylegetson
kylegetson / gist:5595268
Created May 16, 2013 21:31
memory leak example in levelup. Repeatedly getting the same key from leveldb. This will consume 100M in memory within 45 seconds, and continues to grow the more you call db.get()
var levelup = require('levelup')
, crypto = require('crypto');
var db = levelup('./mydb', {cacheSize: 0});
// assuming this key exists
var str = "whatever";
var hash = crypto.createHash('md5').update( str ).digest("hex");
function sameGet(num){
@kylegetson
kylegetson / gist:5599592
Created May 17, 2013 14:56
similar issue with leveldb (level down)
var levelup = require('levelup')
, crypto = require('crypto');
var db = levelup('./mydb', {cacheSize: 0});
function uniqueGet(num){
if( num == 0 ) return;
var hash = crypto.createHash('md5').update( num.toString() ).digest("hex");
@kylegetson
kylegetson / gist:5599722
Created May 17, 2013 15:13
get or set example
var levelup = require('levelup');
var db = levelup('./mydb', {cacheSize: 0});
function getOrSet(num){
if( num == 0 ) return;
var hash = num.toString();
db.get(hash, function(err,result){