public
Created

Evaluating memory consumption of 1M targeted tag sets

  • Download Gist
intset.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
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");
})
})

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.