Skip to content

Instantly share code, notes, and snippets.

@dspezia
Created June 19, 2012 20:06
Show Gist options
  • Save dspezia/2956241 to your computer and use it in GitHub Desktop.
Save dspezia/2956241 to your computer and use it in GitHub Desktop.
Evaluating memory consumption of 1M targeted tag sets
var redis = require('redis')
var rc = redis.createClient(6379, 'localhost');
function create( target, callback )
{
x = []
for ( var i=0; i<40; ++i )
{
// Only 100K entries in the reverse index
var n = 1000*Math.round(Math.random()*100000);
x.push(n);
}
var multi = rc.multi()
multi.sadd( "tgt:"+target, x )
x.forEach( function( xn ) {
multi.sadd( "tag:"+xn, target )
});
multi.exec( function(err,replies) {
callback()
});
}
function filln( offset, N, callback )
{
var count = 0;
for ( i=0; i<N; ++i ) {
create(offset+i, function () {
count++;
if ( count == N )
callback()
})
}
}
function fill( N, i, callback )
{
if ( i >= N/1000 ) {
callback();
return
}
filln( i*1000, 1000, function() {
console.log( "Done",i);
fill( N, ++i, callback )
});
}
rc.flushall( function(err,rr) {
fill( 1000000, 0, function() {
console.log("end");
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment