Skip to content

Instantly share code, notes, and snippets.

@nathanwdavis
Forked from timcash/zeromq_pub.js
Created April 13, 2011 18:03
Show Gist options
  • Save nathanwdavis/918032 to your computer and use it in GitHub Desktop.
Save nathanwdavis/918032 to your computer and use it in GitHub Desktop.
a more refined version of https://gist.github.com/907514 - a test for publish speed of zeromq in nodejs
var cnt, mes, s, sender, util, zmq, ms;
ms = 1000;
zmq = require('zeromq');
util = require('util');
s = zmq.createSocket('pub');
s.bind('tcp://127.0.0.1:5559', function(err) {
if (err) {
throw err;
}
util.puts('binding');
});
cnt = 1;
mes = function() {
var data;
data = "" + cnt;
if (cnt % 100 === 0) {
util.puts("sending " + data);
}
s.send(data);
cnt++;
};
process.on('SIGINT', function() {
clearInterval(sender);
s.close();
console.log("Quitting now");
process.exit(1);
});
util.puts('Ready to go!');
sender = setInterval(mes, 0);
setTimeout(function() {
util.puts('Sent '+ cnt +' in '+ ms +' milliseconds');
process.kill(process.pid, 'SIGINT');
}, ms);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment