Skip to content

Commit

Permalink
another pub/sub strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
dvv committed Jul 1, 2011
1 parent 9a4e51e commit cc2c3f7
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 14 deletions.
10 changes: 6 additions & 4 deletions tests/stress/codec.js
Expand Up @@ -3,12 +3,14 @@ var json = {
decode: JSON.parse
};

/*var msgpack = require('node-msgpack');
var MsgPack = require('node-msgpack');
msgpack = {
encode: msgpack.pack,
decode: msgpack.unpack
};*/
encode: MsgPack.pack,
decode: function(str) { return MsgPack.unpack(new Buffer(str)); }
};

bison = require('bison');

module.exports = json;
//module.exports = msgpack;
module.exports = bison;
4 changes: 2 additions & 2 deletions tests/stress/pubsub/pub.js
Expand Up @@ -6,8 +6,8 @@ var codec = require('../codec');
var sent = 0;

var pub = require('redis').createClient(null, null, {
command_queue_high_water: 5,
command_queue_low_water: 1
//command_queue_high_water: 5,
//command_queue_low_water: 1
})
.on('ready', function() {
this.emit('drain');
Expand Down
42 changes: 34 additions & 8 deletions tests/stress/rpushblpop/pub.js
@@ -1,13 +1,39 @@
'use strict';

var freemem = require('os').freemem;
var codec = require('../codec');

var pub = require('redis').createClient()
.on('ready', function() {
while (true) {
pub.rpush('timeline', codec.encode({
cmd: Math.random(),
data: Math.random()
}));
}
var sent = 0;

var pub = require('redis').createClient(null, null, {
//command_queue_high_water: 5,
//command_queue_low_water: 1
})
.on('ready', function() {
this.del('timeline');
this.emit('drain');
})
.on('drain', function() {
process.nextTick(exec);
});

var payload = '1'; for (var i = 0; i < 10; ++i) payload += payload;

function exec() {
pub.rpush('timeline', codec.encode({ foo: payload }));
++sent;
if (!pub.should_buffer) {
process.nextTick(exec);
}
}

exec();

setInterval(function() {
pub.llen('timeline', function(err, result) {
console.log('sent', sent, 'free', freemem(),
'cmdqlen', pub.command_queue.length, 'offqlen', pub.offline_queue.length,
'llen', result
);
});
}, 1000);

0 comments on commit cc2c3f7

Please sign in to comment.